ASP.NET ListItem TextProperty
ListItem Control
Definition and Usage
The Text property is used to set or return the text of the ListItem control.
Syntax
<asp:ListItem Text="string" runat="server" />
| Properties | Description |
|---|---|
| string | A string value that specifies the text of the ListItem control. |
It is possible to use the Text or Value property as well as inner HTML text to set the displayed text of the list item.
Example
<asp:ListItem Value="Text1" Text="Text2">Text3</asp:ListItem>
Depending on the combination of the Text or Value property and 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 | 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:Since both the Text and Value properties have empty string default values, there may be empty list items in the list control.
Example
The following example sets the ListItem text in a ListBox control:
<form runat="server">
<asp:ListBox runat="server">
<asp:ListItem Text="Item1" />
<asp:ListItem Text="Item2" />
</asp:ListBox>
</form>
<asp:ListBox runat="server">
<asp:ListItem Text="Item1" />
<asp:ListItem Text="Item2" />
</asp:ListBox>
</form>
Show example »
ListItem Control Other extensions