?
Solved

Asp.net 2.0 tableadapter data to a label

Posted on 2007-11-23
4
Medium Priority
?
596 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 1500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

850 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