Latest web development tutorials

ASP.NET ListItem Value property

ListItem control ListItem control

Definition and Usage

Value property is used to set or return the value of the ListItem control.

grammar

<asp:ListItem Value="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 values:

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 values:

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

The demonstration >>

ListItem control ListItem control