ASP.NET ListItem ValueProperty
ListItem Control
Definition and Usage
The Value property is used to set or return the value of the ListItem control.
Syntax
<asp:ListItem Value="string" runat="server" />
| Property | Description |
|---|---|
| string | A string value that specifies the value of the ListItem control. |
It is possible to use the Text or Value property, along with inner HTML text, to set the text displayed for the list item.
Example
<asp:ListItem Value="Text1" Text="Text2">Text3</asp:ListItem>
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 table below lists all possible combinations and their values:
| Inner HTML | Text property | Value property | Displayed text | Value used |
|---|---|---|---|---|
| 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:Because the Text and Value properties both have an empty string as their default value, there can be empty list items in the list control.
Example
The following example sets the value of a ListItem in a ListBox control:
<form runat="server">
<asp:ListBox runat="server">
<asp:ListItem Value="Item1" />
<asp:ListItem Value="Item2" />
</asp:ListBox>
</form>
<asp:ListBox runat="server">
<asp:ListItem Value="Item1" />
<asp:ListItem Value="Item2" />
</asp:ListBox>
</form>
Demo Example »
ListItem Control Other Extensions