aspxtreme

Allowing Users to Select Items in a DataList Control

Controls You Can Use on Web Forms   ASP.NET Data Controls   DataList Control


The DataList control can be set to allow users to select individual items in the list.

This is enabled basically by providing a command-type button control in the DataList's ItemTemplate that, essentially, serves to select the item. The button control can be an <asp:Button>, <asp:LinkButton> or <asp:ImageButton> bound to a field in the data source.

NOTE: The buttons do not automatically select the item. Instead, each button raises an ItemCommand event when clicked, which typically is used to trigger a handler that sets the item associated with the event into selected mode.

When an individual item is selected, the DataList can be set to display additional text and controls for the SelectedItem, that may be different from, or not included in, the ItemTemplate. This is done by defining a SelectedItemTemplate, that is rendered only for whichever item is currently selected.

The DataList also encapsulates the functionality to easily highlight the selected item visually, using the SelectedItemStyle property.

The following examples demonstrate different ways of enabling users to select an item from a DataList.

DataList ItemCommand Event
Run Sample | View Source
DataList SelectedItem Property
Run Sample | View Source
DataList SelectedItemStyle Property
Run Sample | View Source

Now let's take a closer look at how all these are done.



Books and more ...


Suggested Reading

Need a break ?


More ...
Back to top

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support aspxtreme