?
Solved

How to capture the DataTextField Value?

Posted on 2006-04-02
6
Medium Priority
?
293 Views
Last Modified: 2010-04-16

Dear Experts,
   
In VS 2005, I have a DropDownList having DataTextField="FullName" and DataValueField="ApprovedBy".

To get the DataValueFiled Value = this.ApprovedBy.SelectedValue. Although the display is readable as "Jaime Jegonia", how can I capture that Fullname "Jaime Jegonia" so I can use it for whatever  purpose in the program?

Thanks,


Jimi J
   
This is the ASPX tag:
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
            DataTextField="FullName" DataValueField="ApprovedBy">
        </asp:DropDownList>
0
Comment
Question by:JaimeJegonia
  • 4
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
e1v earned 750 total points
ID: 16354194

DropDownList1.SelectedItem.Text
0
 

Author Comment

by:JaimeJegonia
ID: 16354716


DropDownList1.SelectedItem.Text  is always = DropDownList1.SelectedValue
0
 

Author Comment

by:JaimeJegonia
ID: 16354737
elv,

Sorry, you are right. I just tried it's OK. Before I was using interchangeably SelectedItem.Text  & SelectedValue, I always get the same result. Can you explain to me why?


Thanks,


Jimi J
0
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!

 

Author Comment

by:JaimeJegonia
ID: 16354793
How can I fill or bind the DropDownList with Datareader so that  I can always both the Text and Value?

if I use DropdownList.Items.Add(index, ListItem) - I can only get either TextField or ValueField.


Thanks,

Jimi J
0
 
LVL 6

Expert Comment

by:e1v
ID: 16355115
You can use DropDownList.Items.Add(new ListItem("text", "value")) or  DropDownList.Items.Insert(index, new ListItem("text", "value"))  to add a listitem with value and text.

if you use Items.Add("string") the value and text will be the same.
0
 

Author Comment

by:JaimeJegonia
ID: 16357025
elv,

I got it. Thank you very much!

Jimi J
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

840 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