Latest web development tutorials

ASP.NET ListItem Text property

ListItem control ListItem control

Definition and Usage

Text property sets or returns the text ListItem control.

grammar

<asp:ListItem Text="string" runat="server" />

属性 描述
string 字符串值,规定 ListItem 控件的文本。

It is possible to use the Text or Value properties and the inner HTML text to set the text list entries.

Examples

<asp:ListItem Value="Text1" Text="Text2">Text3</asp:ListItem>

According to Text or Value properties and the combination of inner HTML text to display different text, and use a different value. The following table lists all the possible combinations and their results:

Inner HTML Text 属性 Value 属性 显示的文本 使用的值
已设置 已设置 已设置 Inner HTML Value 属性
已设置 已设置 未设置 Inner HTML Inner HTML
已设置 未设置 已设置 Inner HTML Value 属性
已设置 未设置 未设置 Inner HTML Inner HTML
未设置 已设置 已设置 Text 属性 Value 属性
未设置 已设置 未设置 Text 属性 Text 属性
未设置 未设置 已设置 Value 属性 Value 属性
未设置 未设置 未设置 未设置 未设置


Tips and Notes

Note: Due to Text and Value property has an empty string default values, so the list of controls may empty list item.


Examples

The following example sets the ListBox control ListItem text:

<form runat="server">
<asp:ListBox runat="server">
<asp:ListItem Text="Item1" />
<asp:ListItem Text="Item2" />
</asp:ListBox>
</form>

The demonstration >>

ListItem control ListItem control