| | |
Regarding ListItem Class
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
![]() |
•
•
Join Date: Jul 2004
Posts: 4
Reputation:
Solved Threads: 0
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
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
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.
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.
-Ryan Hoffman
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
And to add to that just set the following from your connection to the DB:
:lol:
' ||||| 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:
![]() |
Similar Threads
- Software Engineer (Java)
- Class Troubles... (C++)
- java and using observable class (Java)
- "missing storage-class or type specifiers" error (C++)
- first math class in uni (Geeks' Lounge)
Other Threads in the ASP.NET Forum
- Previous Thread: Porting asp to asp.NET (with fileup)
- Next Thread: Log In Failure
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# c#gridviewcolumn cac checkbox class commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist development dgv dropdownlist dropdownmenu dynamically edit fileuploader fill flash flv formatdecimal forms formview gridview gudi homeedition iframe iis javascript jquery listbox menu microsoft mouse mssql multistepregistration nameisnotdeclared news objects opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice youareanotmemberofthedebuggerusers




