Link to home
Start Free TrialLog in
Avatar of martin05
martin05

asked on

Asp.net 2.0 tableadapter data to a label

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
Avatar of DJFuller
DJFuller
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of martin05
martin05

ASKER

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
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.
ASKER CERTIFIED SOLUTION
Avatar of DJFuller
DJFuller
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial