TDataList class
TDataList represents a data bound and updatable list control.
Like TRepeater, TDataList displays its content repeatedly based on the data fetched from DataSource. The repeated contents in TDataList are called items, which are controls and can be accessed through Items. When dataBind() is invoked, TDataList creates an item for each row of data and binds the data row to the item. Optionally, a TDataList can have a header, a footer and/or separators between items.
TDataList differs from TRepeater in that it supports tiling the items in different manners and it maintains status of items to handle data update.
The layout of the repeated contents are specified by inline templates. TDataList items, header, footer, etc. are being instantiated with the corresponding templates when data is being bound to the repeater.
Since v3.1.0, the layout can also be by renderers. A renderer is a control class that can be instantiated as datalist items, header, etc. A renderer can thus be viewed as an external template (in fact, it can also be non-templated controls).
A renderer can be any control class.
property will be set as the data row during databinding. Many PRADO controls implement this interface, such as
TLabel,
TTextBox, etc.
as the zero-based index of the item in the datalist item collection, and the
ItemType property as the item's type (such as TListItemType::Item).
TDataListItemRenderer may be used as the convenient base class which already implements IDataItemRenderer.
The following properties are used to specify different types of template and renderer for a datalist:
for each repeated row of data
for each alternating row of data. If not set,
ItemTemplate or
ItemRenderer will be used instead.
for the datalist header.
for the datalist footer.
for content to be displayed between items.
used when data bound to the datalist is empty.
for the row being editted.
for the row being selected.
If a content type is defined with both a template and a renderer, the latter takes precedence.
When dataBind() is being called, TDataList undergoes the following lifecycles for each row of data:
- create item based on templates or renderers
- set the row of data to the item
- raise OnItemCreated:
- add the item as a child control
- call dataBind() of the item
- raise OnItemDataBound:
TDataList raises an
OnItemCommand whenever a button control within some datalist item raises a
OnCommand event. Therefore, you can handle all sorts of
OnCommand event in a central place by writing an event handler for
OnItemCommand.
An additional event is raised if the OnCommand event has one of the following command names:
- edit: user wants to edit an item. OnEditCommand event will be raised.
- update: user wants to save the change to an item. OnUpdateCommand event will be raised.
- select: user selects an item. OnSelectedIndexChanged event will be raised.
- delete: user deletes an item. OnDeleteCommand event will be raised.
- cancel: user cancels previously editting action. OnCancelCommand event will be raised.
TDataList provides a few properties to support tiling the items. The number of columns used to display the data items is specified via
RepeatColumns property, while the
RepeatDirection governs the order of the items being rendered. The layout of the data items in the list is specified via
RepeatLayout, which can take one of the following values:
- Table (default): items are organized using HTML table and cells.
When using this layout, one can set
CellPadding and
CellSpacing to adjust the cellpadding and cellpadding of the table, and
Caption and
CaptionAlign to add a table caption with the specified alignment.
- Flow: items are organized using HTML spans and breaks.
- Raw: TDataList does not generate any HTML tags to do the tiling.
Items in TDataList can be in one of the three status: normal browsing, being editted and being selected. To change the status of a particular item, set
SelectedItemIndex or
EditItemIndex. The former will change the indicated item to selected mode, which will cause the item to use
SelectedItemTemplate or
SelectedItemRenderer for presentation. The latter will change the indicated item to edit mode and to use corresponding template or renderer. Note, if an item is in edit mode, then selecting this item will have no effect.
Different styles may be applied to items in different status. The style application is performed in a hierarchical way: Style in higher hierarchy will inherit from styles in lower hierarchy. Starting from the lowest hierarchy, the item styles include
Therefore, if background color is set as red in
ItemStyle,
EditItemStyle will also have red background color unless it is set to a different value explicitly.
When a page containing a datalist is post back, the datalist will restore automatically all its contents, including items, header, footer and separators. However, the data row associated with each item will not be recovered and become null. To access the data, use one of the following ways:
- Use DataKeys to obtain the data key associated with
the specified datalist item and use the key to fetch the corresponding data from some persistent storage such as DB.
- Save the whole dataset in viewstate, which will restore the dataset automatically upon postback.
Be aware though, if the size of your dataset is big, your page size will become big. Some complex data may also have serializing problem if saved in viewstate.
| Method Summary |
|
protected
void
|
Applies styles to items, header, footer and separators.
|
|
boolean
|
This method overrides parent's implementation to handle onItemCommand event which is bubbled from datalist items and their child controls.
|
|
protected
void
|
Creates empty datalist content.
|
|
protected
TControl
|
Creates a datalist item instance based on the item type and index.
|
|
TStyle
|
Returns a style used for rendering items.
|
|
string
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
string
|
|
|
TTableCaptionAlign
|
|
|
TControl
|
|
|
integer
|
|
|
string
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
string
|
|
|
ITemplate
|
|
|
TControl
|
|
|
string
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
boolean
|
Returns a value indicating whether this control contains footer item.
|
|
boolean
|
Returns a value indicating whether this control contains header item.
|
|
boolean
|
Returns a value indicating whether this control contains separator items.
|
|
TControl
|
|
|
string
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
integer
|
|
|
string
|
|
|
TDataListItemCollection
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
integer
|
|
|
TRepeatDirection
|
|
|
protected
TRepeatInfo
|
|
|
TRepeatLayout
|
|
|
mixed
|
|
|
TControl
|
|
|
integer
|
|
|
string
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
string
|
|
|
TTableItemStyle
|
|
|
ITemplate
|
|
|
boolean
|
|
|
boolean
|
|
|
void
|
Loads item count information from viewstate.
|
|
void
|
Raises OnCancelCommand event.
|
|
void
|
Raises OnDeleteCommand event.
|
|
void
|
Raises OnEditCommand event.
|
|
void
|
Raises OnItemCommand event.
|
|
void
|
Raises OnItemCreated event.
|
|
void
|
Raises OnItemDataBound event.
|
|
void
|
Raises OnUpdateCommand event.
|
|
protected
void
|
Performs databinding to populate data list items from data source.
|
|
void
|
Renders the data list control.
|
|
void
|
Renders an item in the list.
|
|
void
|
Clears up all items in the data list.
|
|
protected
void
|
Creates data list items based on viewstate information.
|
|
void
|
Saves item count in viewstate.
|
|
void
|
Sets the alternative item renderer class.
|
|
void
|
|
|
void
|
|
|
TTableCaptionAlign
|
|
|
void
|
Edits an item by its index in getItems.
|
|
void
|
Sets the renderer class for the datalist item being editted.
|
|
void
|
|
|
void
|
Sets the datalist empty renderer class.
|
|
void
|
|
|
void
|
Sets the datalist footer renderer class.
|
|
void
|
|
|
void
|
Sets the datalist header renderer class.
|
|
void
|
|
|
void
|
Sets the item renderer class.
|
|
void
|
|
|
void
|
|
|
void
|
|
|
void
|
|
|
void
|
Selects an item by its index in getItems.
|
|
void
|
Sets the renderer class for the datalist item being selected.
|
|
void
|
|
|
void
|
Sets the datalist item separator renderer class.
|
|
void
|
|
|
void
|
|
|
void
|
|