From 97606c15be1435c8b910a43812834330032acc75 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 9 Feb 2007 21:34:53 +0000 Subject: updated datalist tutorial page. --- .../protected/pages/Controls/DataList.page | 112 +++++++++++++++------ 1 file changed, 81 insertions(+), 31 deletions(-) (limited to 'demos/quickstart/protected/pages/Controls') diff --git a/demos/quickstart/protected/pages/Controls/DataList.page b/demos/quickstart/protected/pages/Controls/DataList.page index 909fd6dc..66ae8511 100644 --- a/demos/quickstart/protected/pages/Controls/DataList.page +++ b/demos/quickstart/protected/pages/Controls/DataList.page @@ -2,60 +2,110 @@

TDataList

-TDataList is used to display or modify a list of data items specified by its DataSource or DataSourceID property. Each data item is displayed by a data list item which is a child control of the data list. The Items property contains the list of all data list items. +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 displays its items in either a Table or Flow layout, which is specified by the RepeatLayout property. A table layout uses HTML table cells to organize the items while a flow layout uses line breaks to organize the items. When the layout is Table, the table's cellpadding and cellspacing can be adjusted by CellPadding and CellSpacing properties, respectively. And Caption and CaptionAlign can be used to add a table caption with the specified alignment. The number of columns used to display the data list items is specified via RepeatColumns property, while the RepeatDirection governs the order of the items being rendered. +TDataList differs from TRepeater in that it introduces the concept of item state and allows applying different styles to items in different states. In addition, TDataList supports tiling the repeated items in various ways.

+

-Each data list item is created according to one of the seven kinds of templates that developers may specified for a TDataList, +The layout of the repeated contents in TDataList 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.

- +

-Each of the above templates is associated with a style property that is applied to the items using the template. For example, ItemTemplate is associated with a property named AlternatingItemStyle. Through this property, one can set CSS style fields or CSS classes for the data list items. +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). For more details, see the explanation about renderer in the TRepeater tutorial.

+

-Item styles are applied in a hierarchical way. Style in higher hierarchy will inherit from styles in lower hierarchy. Starting from the lowest hierarchy, the item styles include item's own style, ItemStyle, AlternatingItemStyle, SelectedItemStyle, and EditItemStyle. Therefore, if background color is set as red in ItemStyle, EditItemStyle will also have red background color, unless it is explicitly set to a different value. +The following properties are used to specify different types of template and renderer for a datalist. If a content type is defined with both a template and a renderer, the latter takes precedence.

+ + +

-A data list item can be in normal mode, edit mode or selected mode. Different templates will apply to items of different modes. To change an item's mode, modify EditItemIndex or SelectedItemIndex. Note, if an item is in edit mode, then selecting this item will have no effect. +When dataBind() is called, TDataList undergoes the following lifecycles for each row of data:

+ +
    +
  1. create item based on templates or renderers
  2. +
  3. set the row of data to the item
  4. +
  5. raise an OnItemCreated event
  6. +
  7. add the item as a child control
  8. +
  9. call dataBind() of the item
  10. +
  11. raise an OnItemDataBound event
  12. +
+

-TDataList provides several events to facilitate manipulation of its items, +TDataList raises an OnItemCommand whenever a button control within some datalist item raises an 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 (case-insensitive):

+ +

+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 takes one of the following values: +

+ + + +

+Items in TDataList can be in one of the three states: being browsed, being editted and being selected. To change the state 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: +

+ + +

The following example shows how to use TDataList to display tabular data, with different layout and styles.

-

+

A common use of TDataList is for maintaining tabular data, including browsing, editing, deleting data items. This is enabled by the command events and various item templates of TDataList.

-

+

The following example displays a computer product information. Users can add new products, modify or delete existing ones. In order to locate the data item for updating or deleting, DataKeys property is used.

-

+

Be aware, for simplicity, this application does not do any input validation. In real applications, make sure user inputs are valid before saving them into databases.

-- cgit v1.2.3