Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Asp.net 2.0 tableadapter data to a label

Posted on 2007-11-23
4
Medium Priority
?
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

610 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