ASP.NET Tutoria...login
ASP.NET Tutorial
author:php.cn  update time:2022-04-11 14:18:18

ListItem control


ASP.NET ListItem Control


up.gif Web server control

Definition and usage

The ListItem control can Create an item in the list.

This control is used together with the following list controls: <asp:ListBox>, <asp:RadioButtonList> and <asp:BulletedList>.


Syntax

<asp:ListItem
Enabled="True|False"
Selected="True|False"
Text=" label"
Value="value" />

Attribute

##AttributeDescription.NETAttributes Optional. A collection of property name and value pairs for ListItems that this class does not directly support. 1.0Enabled Optional. Specifies whether to disable or enable the item. 2.0Selected Optional. Specifies whether this item is selected. 1.0Text Optional. The text displayed in the ListItem. 1.0Value Optional. The value of the ListItem. 1.0

Web control standard properties

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width

For a complete description, visit Web Control Standard Properties.

Control standard properties

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible

For a complete description, visit Control Standard Properties.

It is possible to set the text of the displayed list item using the Text or Value property along with the inner HTML text.

Example

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

Based on Combinations of the Text or Value attribute and inner HTML text can display different text and use different values. The following table lists all possible combinations and their results:

Inner HTMLText attributeValue attributeText displayedValue used
setsetsetInner HTMLValue attribute
SetSetNot setInner HTML Inner HTML
SetNot setSetInner HTMLValue attribute
SetNot setNot setInner HTMLInner HTML
Not setSetSetText property Value property
Not setSetNot setText property Text property
Not setNot setSetValue propertyValue property
Not setNot setNot setNot setNot set


Tips and Notes

Notes: Since both the Text and Value properties have empty string default values, it is possible to have empty list items in the list control.


Example

BulletedList with basic ListItem
This example shows a BulletedList control with two ListItems in an .aspx file.

ListBox with ListItems with different properties
This example shows a ListBox control with several ListItems in an .aspx file. The items in the list use different properties to display the text of the ListItem.

ListBox with disabled ListItem
This example shows a ListBox control with disabled ListItem.

RadioButtonList with selected ListItem
This example shows a RadioButtonList control with selected ListItem.


up.gif Web Server Control

php.cn