ASP.NET ListItem
Control
Definition and Usage
The ListItem control creates an item in a list.
This control is used with the following list controls: <asp:ListBox>, <asp:RadioButtonList>, and <asp:BulletedList>.
Syntax
Properties
Property | Description | .NET |
---|---|---|
Attributes | Optional. A collection of attribute name and value pairs for the ListItem that are not directly supported by this class. | 1.0 |
Enabled | Optional. Specifies whether the item is disabled or enabled. | 2.0 |
Selected | Optional. Specifies whether the item is selected. | 1.0 |
Text | Optional. The text displayed in the ListItem. | 1.0 |
Value | Optional. The value of the ListItem. | 1.0 |
Web Control Standard Properties
For a full description, visit Web Control Standard Properties.
Control Standard Properties
For a full description, visit Control Standard Properties.
It is possible to set the text displayed for the list item using either the Text or Value property, as well as the inner HTML text.
Examples
Depending on the combination of the Text or Value property and the inner HTML text, different text can be displayed and different values can be used. The following table lists all possible combinations and their results:
Inner HTML | Text Property | Value Property | Displayed Text | Used Value |
---|---|---|---|---|
Set | Set | Set | Inner HTML | Value Property |
Set | Set | Not Set | Inner HTML | Inner HTML |
Set | Not Set | Set | Inner HTML | Value Property |
Set | Not Set | Not Set | Inner HTML | Inner HTML |
Not Set | Set | Set | Text Property | Value Property |
Not Set | Set | Not Set | Text Property | Text Property |
Not Set | Not Set | Set | Value Property | Value Property |
Not Set | Not Set | Not Set | Not Set | Not Set |
Tips and Notes
Note: Since both the Text and Value properties have an empty string default value, there may be empty list items in the list control.
Examples
BulletedList with Basic ListItem
ListBox with ListItem with Different Properties
ListBox with Disabled ListItem
RadioButtonList with Selected ListItem