summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Controls/Repeater.page
diff options
context:
space:
mode:
authorxue <>2007-02-06 22:44:55 +0000
committerxue <>2007-02-06 22:44:55 +0000
commit2a962765f0b687988384294cdb4baf51e291680c (patch)
treec9fe1e10d7ed8b54a92952dfc32e989ec861d97f /demos/quickstart/protected/pages/Controls/Repeater.page
parent34688be706935b1c0bbcc373849c0a9824ec9d21 (diff)
updated QS pages.
Diffstat (limited to 'demos/quickstart/protected/pages/Controls/Repeater.page')
-rw-r--r--demos/quickstart/protected/pages/Controls/Repeater.page83
1 files changed, 62 insertions, 21 deletions
diff --git a/demos/quickstart/protected/pages/Controls/Repeater.page b/demos/quickstart/protected/pages/Controls/Repeater.page
index cc642c5a..69c6cdba 100644
--- a/demos/quickstart/protected/pages/Controls/Repeater.page
+++ b/demos/quickstart/protected/pages/Controls/Repeater.page
@@ -1,20 +1,39 @@
<com:TContent ID="body" >
<h1 id="5301">TRepeater</h1>
+
<p id="600400" class="block-content">
-TRepeater displays its content defined in templates repeatedly based on the given data specified by the <tt>DataSource</tt> or <tt>DataSourceID</tt> property. The repeated contents can be retrieved from the <tt>Items</tt> property. Each item is created by instantiating a template and each is a child control of the repeater.
+TRepeater displays its content repeatedly based on the data fetched from <tt>DataSource</tt>. The repeated contents in TRepeater are called <i>items</i> which are controls accessible through <tt>Items</tt> property. When <tt>dataBind()</tt> is invoked, TRepeater creates an item for each row of data and binds the data row to the item. Optionally, a repeater can have a header, a footer and/or separators between items.
</p>
+
<p id="600401" class="block-content">
-Like normal control templates, the repeater templates can contain static text, controls and special tags, which after instantiation, become child contents of the corresponding item. TRepeater defines five templates for different purposes,
+The layout of the repeated contents are specified by inline templates. In particular, repeater items, header, footer, etc. are being instantiated with the corresponding templates when data is being bound to the repeater.
+</p>
+
+<p id="600402" class="block-content">
+Since v3.1.0, the layout can also be specified by <i>renderers</i>. A renderer is a control class that can be instantiated as repeater 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. If implemented with one of the following interfaces, a renderer will be initialized with additional properties relevant to the repeater items:
</p>
+
<ul id="u1" class="block-content">
- <li><tt>HeaderTemplate</tt> - the template used for displaying content at the beginning of a repeater;</li>
- <li><tt>FooterTemplate</tt> - the template used for displaying content at the end of a repeater;</li>
- <li><tt>ItemTemplate</tt> - the template used for displaying every repeater item. If <tt>AlternatingItemTemplate</tt> is also defined, <tt>ItemTemplate</tt> will be used for displaying item 1, 3, 5, etc.</li>
- <li><tt>AlternatingItemTemplate</tt> - the template used for displaying every alternating repeater item (i.e., item 2, 4, 6, etc.)</li>
- <li><tt>SeparatorTemplate</tt> - the template used for displaying content between items.</li>
+<li><tt>IDataRenderer</tt> - the <tt>Data</tt> property will be set as the row of the data bound to the repeater item. Many PRADO controls implement this interface, such as <tt>TLabel</tt>, <tt>TTextBox</tt>, etc.</li>
+<li><tt>IItemDataRenderer</tt> - the <tt>ItemIndex</tt> property will be set as the zero-based index of the item in the repeater item collection, and the <tt>ItemType</tt> property as the item's type (such as <tt>TListItemType::Item</tt>). As a convenient base class, <tt>TRepeaterItemRenderer</tt> implements <tt>IDataItemRenderer</tt> and can have an associated template because it extends from <tt>TTemplateControl</tt>.</li>
</ul>
-<p id="600402" class="block-content">
+
+
+<p id="600403" class="block-content">
+The following properties are used to specify different types of template and renderer for a repeater. If an item type is defined with both a template and a renderer, the latter takes precedence.
+</p>
+<ul id="u2" class="block-content">
+<li><tt>ItemTemplate</tt>, <tt>ItemRenderer</tt> - for each repeated row of data.</li>
+<li><tt>AlternatingItemTemplate</tt>, <tt>AlternatingItemRenderer</tt>: for each alternating row of data. If not set, <tt>ItemTemplate</tt> or <tt>ItemRenderer</tt> will be used instead, respectively.</li>
+<li><tt>HeaderTemplate</tt>, <tt>HeaderRenderer</tt> - for the repeater header.</li>
+<li><tt>FooterTemplate</tt>, <tt>FooterRenderer</tt> - for the repeater footer.</li>
+<li><tt>SeparatorTemplate</tt>, <tt>SeparatorRenderer</tt> - for content to be displayed between items.</li>
+<li><tt>EmptyTemplate</tt>, <tt>EmptyRenderer</tt> - used when data bound to the repeater is empty.</li>
+</ul>
+
+
+<p id="600404" class="block-content">
To populate data into the repeater items, set <tt>DataSource</tt> to a valid data object, such as array, <tt>TList</tt>, <tt>TMap</tt>, or a database table, and then call <tt>dataBind()</tt> for the repeater. That is,
</p>
<com:TTextHighlighter Language="php" CssClass="source block-content" id="code_600125">
@@ -28,32 +47,54 @@ class MyPage extends TPage {
}
}
</com:TTextHighlighter>
-<p id="600403" class="block-content">
-Normally, you only need to do this when the page containing the repeater is initially requested. In postbacks, TRepeater is smart enough to remember the previous state, i.e., contents populated with datasource information.The following sample displays tabular data using TRepeater.
+
+<p id="600405" class="block-content">
+When <tt>dataBind()</tt> is called, TRepeater undergoes the following lifecycles for each row of data:
</p>
-<p id="600404" class="block-content">
-TRepeater provides several events to facilitate manipulation of its items,
+
+<ol id="u3" class="block-content">
+<li>create item based on templates or renderers</li>
+<li>set the row of data to the item</li>
+<li>raise an <tt>OnItemCreated</tt> event</li>
+<li>add the item as a child control</li>
+<li>call <tt>dataBind()</tt> of the item</li>
+<li>raise an <tt>OnItemDataBound</tt> event</li>
+</ol>
+
+<p id="600406" class="block-content">
+Normally, you only need to bind the data to repeater when the page containing the repeater is initially requested. When the page is post back, the repeater 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 thus become null.
</p>
-<ul id="u2" class="block-content">
- <li><tt>OnItemCreated</tt> - raised each time an item is newly created. When the event is raised, data and child controls are both available for the new item.</li>
- <li><tt>OnItemDataBound</tt> - raised each time an item just completes databinding. When the event is raised, data and child controls are both available for the item, and the item has finished databindings of itself and all its child controls.</li>
- <li><tt>OnItemCommand</tt> - raised when a child control of some item (such as a <tt>TButton</tt>) raises an <tt>OnCommand</tt> event.</li>
+
+<p id="600407" class="block-content">
+To access the repeater item data in postbacks, use one of the following ways:
+</p>
+<ul id="u4" class="block-content">
+<li>Use <tt>DataKeys</tt> to obtain the data key associated with the specified repeater item and use the key to fetch the corresponding data from some persistent storage such as DB. </li>
+<li>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.</li>
</ul>
-<p id="600405" class="block-content">
+
+
+<p id="600408" class="block-content">
+TRepeater raises an <tt>OnItemCommand</tt> event whenever a button control within some repeater item raises a <tt>OnCommand</tt> event. Therefore,
+you can handle all sorts of <tt>OnCommand</tt> event in a central place by
+writing an event handler for <tt>OnItemCommand</tt>.
+</p>
+
+<p id="600409" class="block-content">
The following example shows how to use TRepeater to display tabular data.
</p>
<com:RunBar PagePath="Controls.Samples.TRepeater.Sample1" />
-<p id="600406" class="block-content">
+<p id="600410" class="block-content">
TRepeater can be used in more complex situations. As an example, we show in the following how to use nested repeaters, i.e., repeater in repeater. This is commonly seen in presenting master-detail data. To use a repeater within another repeater, for an item for the outer repeater is created, we need to set the detail data source for the inner repeater. This can be achieved by responding to the <tt>OnItemDataBound</tt> event of the outer repeater. An <tt>OnItemDataBound</tt> event is raised each time an outer repeater item completes databinding. In the following example, we exploit another event of repeater called <tt>OnItemCreated</tt>, which is raised each time a repeater item (and its content) is newly created. We respond to this event by setting different background colors for repeater items to achieve alternating item background display. This saves us from writing an <tt>AlternatingItemTemplate</tt> for the repeaters.
</p>
<com:RunBar PagePath="Controls.Samples.TRepeater.Sample2" />
-<p id="600407" class="block-content">
+<p id="600411" class="block-content">
Besides displaying data, TRepeater can also be used to collect data from users. Validation controls can be placed in TRepeater templates to verify that user inputs are valid.
</p>
-<p id="600408" class="block-content">
+<p id="600412" class="block-content">
The <a href="../composer/index.php">PRADO component composer</a> demo is a good example of such usage. It uses a repeater to collect the component property and event definitions. Users can also delete or adjust the order of the properties and events, which is implemented by responding to the <tt>OnItemCommand</tt> event of repeater.
</p>
-<p id="600409" class="block-content">
+<p id="600413" class="block-content">
See in the following yet another example showing how to use repeater to collect user inputs.
</p>
<com:RunBar PagePath="Controls.Samples.TRepeater.Sample3" />