943,929 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 4593
  • ASP.NET RSS
Jul 31st, 2004
0

Regarding ListItem Class

Expand Post »
Hi All,
I am using a DropDownList in my page and I am binding the property of this server control like follows.
<%#DropDownList1.SelectedItem.Text%>
What I am finding is that it returns the text for the item I have selected. If I use the value property of the ListItem, then also it returns the text for the item I have selected.
In that case, what is the difference between the text property and the value property of the ListItem class??
I am sorry, if it is a very basic question..
Thanks and Regards,
CSPEK
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cspek is offline Offline
4 posts
since Jul 2004
Jul 31st, 2004
0

Re: Regarding ListItem Class

Value is an object, which each list item has. When you create list items, you can assign a value object to them, and that object will stay with the list item (but not be displayed on the page).

The ideal use for this, is when you have a list of items that corrospond to ID numbers in a database. You would set the text property to the friendly description for the item, and the value to the ID number. When you go to interact with your database, you don't need to parse what ID number has been selected; because it's just in it's Value.
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 31st, 2004
0

Re: Regarding ListItem Class

And to add to that just set the following from your connection to the DB:
     
'   |||||   Set the DataValueField to the Primary Key
DropDownList1.DataValueField = "ID"
' '   |||||   Set the DataTextField to the text/data you want to display
DropDownList1.DataTextField = "Details"

:lol:
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Aug 2nd, 2004
0

Re: Regarding ListItem Class

Yep,
Thanks...
cspek
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cspek is offline Offline
4 posts
since Jul 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in ASP.NET Forum Timeline: Porting asp to asp.NET (with fileup)
Next Thread in ASP.NET Forum Timeline: Log In Failure





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC