We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How to capture the DataTextField Value?

JaimeJegonia
JaimeJegonia asked
on
Medium Priority
306 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>
Comment
Watch Question

Commented:

DropDownList1.SelectedItem.Text

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:


DropDownList1.SelectedItem.Text  is always = DropDownList1.SelectedValue

Author

Commented:
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

Author

Commented:
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
e1v

Commented:
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.

Author

Commented:
elv,

I got it. Thank you very much!

Jimi J
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.