BulletedList Web Server Control Overview
Thecontrol creates an unordered or ordered (numbered) list of items, which renders as an HTML ul or ol element, respectively. You can specify the appearance of the items and of the bullets or numbers, define the list items statically or by binding the control to data, and you can respond to users' clicks on items.
Defining List Items
The BulletedList derives from the sameclass as the , , and other ASP.NET list controls, so using it is similar to working with those controls. You can define list items for the BulletedList control either by creating static items or by binding the control to a data source. If you know at design time what items you want to display, you can set the control's collection to a set of individual items in markup. If the items to be displayed are dynamic, you can create the item collection in code at run time. For details, see .
Alternatively, you can bind the control to a data source that contains the information you want to display. For details, see.
You can combine static and data-bound list items by setting the control'sproperty to true.
When you define items for the BulletedList control, you define two properties: theproperty and the property. The Text property defines what the control displays on the page. The Value property defines a second value that is not displayed but that you might want to return when a user selects an item. For example, you might display an employee name as the text of an item, but use the employee ID as the value; when users click the item, you can read the value directly.
Do not use sensitive data, such as customer numbers, for the value property of a BulletedList control. Even though it is not visible, the Value property settings of individual items are rendered to the page, where users can easily read them in the page's source.
Customizing List Item Appearance
The BulletedList control can render either bullets or numbers, according to the setting of theproperty. If the control is set to render bullets, you can select from predefined bullet style fields that match HTML standard bullet styles, such as those represented by the , , and fields.
Individual browsers vary in how they render bullets, and some browsers do not support certain bullet styles, such as the Disc field.
You can also specify a custom image that will be displayed instead of the bullet.
If the control is set to render numbers, you can likewise select from HTML standard numbering options, such as the, , , and UpperAlpha fields. By setting the property, you can also specify a starting number for the sequence.
Specifying Item Display Mode
The BulletedList control can display list items as any of the following:
Static text The text displayed by the control is not interactive.
T:System.Web.UI.WebControls.HyperLink controls Users can click links to navigate to another page. You must provide a target URL as the Value property of individual items.
controls Users can click individual items and the control performs a postback.
Responding to User Selection
If the BulletedList control is configured to display individual items as LinkButton controls, the control performs a postback when a user clicks an item. The postback raises the BulletedList control'sevent, where you can provide logic to perform application-specific tasks. The event passes to you the index number of the item that was clicked. For details, see .