DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Regarding ListItem Class (http://www.daniweb.com/forums/thread8686.html)

cspek Jul 31st, 2004 7:17 am
Regarding ListItem Class
 
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

Tekmaven Jul 31st, 2004 3:42 pm
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.

Paladine Jul 31st, 2004 6:02 pm
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:

cspek Aug 2nd, 2004 2:50 am
Re: Regarding ListItem Class
 
Yep,
Thanks...
cspek


All times are GMT -4. The time now is 7:52 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC