Solved

Asp.net 2.0 tableadapter data to a label

Posted on 2007-11-23
4
579 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now