Solved

Asp.net 2.0 tableadapter data to a label

Posted on 2007-11-23
4
582 Views
Last Modified: 2013-11-26
I have a table adapter which returns a row from a users table based on a parameter
eg select * from users where username = 'Peter'

This works fine though what i want to do is when it returns the data below,
Username Email                    City
Peter         Pete@Pete.com    Edinburgh

I would like to enter the email value into a label or a Variable...
e.g
Dim SelectedEmail AS String=Useradapter.getalldata(UserID).????EmailField????.AsString
Label1.Text  =Useradapter.getalldata(UserID).????EmailField????.AsString


It must be something stupid but I cant see an easy way to do this although I think it should be simple


Ta
0
Comment
Question by:martin05
  • 3
4 Comments
 
LVL 2

Expert Comment

by:DJFuller
ID: 20338693
Not sure i fully understand.

If you just want to display the results then use a detailsview/formview or gridview control use an objectdatasource to pick out the correct table adapter query.

If you use a control to get the record already and want to use it elsewhere on the page then you need to put the Email in a label within a formview then name the label lblEmail. Then the code behind:

Dim selectedEmail as label = ctype(Formview1.findcontrol("lblEmail"), label)
label1.text = selectedEmail

Hope that helps
0
 

Author Comment

by:martin05
ID: 20338745
Thanks

I will explain exactly what i am trying to do.

I need to enter data from multiple tables into a single table
the users select a user from a dropdown list which gets the username and email phone etc from the database through an objectdatasource.

I want to be able to get the selected email address and store it in a variable selectedemail
so that when my users have finished selecting everyting on the form it inserts it
into my database as
 insert(selecteduser,selectedEmail,fault,dropdownlist2.text)
hope thats a bit clearer
0
 
LVL 2

Expert Comment

by:DJFuller
ID: 20338783
OK, what control are you using to get the username, email etc from the dropdown list?

If it was me, I'd use a detailsview which generated results based on the dropdown list. Name the detailsview "Detailsview1". Go in and edit fields and on email address field "convert to a template field".

Then edit templates and go into item template for the email field. Name the label lblEmail. End template editing.

In the code behind your insert button:

Dim selectedEmail as label = ctype(Detailsview1.findcontrol("lblEmail"), label)
label1.text = selectedEmail

you can repeat this for all the fields you want to extract to a variable and then perform your insert query.
0
 
LVL 2

Accepted Solution

by:
DJFuller earned 500 total points
ID: 20338791
Sorry,

you obviously don't have to set your variable to another label (label1), I just left that for testing.

Dim selectedEmail as label = ctype(Detailsview1.findcontrol("lblEmail"), label)

will give you the variable selectedEmail to use in your insert query.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question