The Repeater control provides maximum flexibility among the three ASP. NET data Web controls: the HTML tags it presents can be specified. The DataGrid or DataList automatically contains the content specified by the developer in the preset HTML Tag. Different from them, the Repeater strictly generates the specified HTML Tag during rendering. Therefore, if you do not want to use HTML
<Table>
Or a series
<Span>
You must use the Repeater control to label and display data in other ways.
Like DataList, the Repeater control must be marked with a template. Repeater contains the following five templates:
AlternatingItemTemplate
FooterTemplate
HeaderTemplate
ItemTemplate
SeparatorTemplate
HeaderTemplate and FooterTemplate specify the HTML Tag that appears before and after the data bound to the Repeater. AlternatingItemTemplate and ItemTemplate specify
DataSource
The HTML Tag and Data Binding Syntax of each record in. For example, if you want to bind a dataset containing employee information to Repeater, one of the fields in the dataset is
EmployeeName
. To display the employee list in an unordered list on the Web page, you can use the following Repeater Syntax:
- < asp:Repeater runat="server" id="rptEmployees">
- < HeaderTemplate>
- < ul>
- < /HeaderTemplate>
- < ItemTemplate>
- < li>< %# DataBinder.Eval(Container.DataItem, "EmployeeName") %>< /li>
- < /ItemTemplate>
- < FooterTemplate>
- < /ul>
- < /FooterTemplate>
- < /asp:Repeater>
Unlike DataGrid and DataList, the Repeater class is not from
WebControl
Class. Therefore, the Repeater lacks the style attributes shared by the DataGrid and DataList. This simply means that if you want to set the format of the data displayed in Repeater, you must perform this operation in the HTML Tag. For example, in the above example, if you want to display the employee name in bold, you must change ItemTemplate to include the HTML bold mark, as shown below:
- < ItemTemplate>
- < li>< b>< %# DataBinder.Eval(Container.DataItem, "EmployeeName")
- %>< /b>< /li>
- < /ItemTemplate>
However, for a DataGrid or DataList
ItemStyle-Font-Bold
If the attribute is set to True, text can be displayed in bold.
The lack of style attributes in the Repeater control greatly increases the development time indicator. For example, if you decide to use Repeater to display data, the data needs to be displayed in a specific font with a specific background color in bold and in the middle alignment. All of these are specified with several HTML tags, which will soon make the Repeater template messy. This clutter makes it much more difficult to change the appearance in the future, especially when others operate on the project, they have to view a large number of HTML syntaxes. Compare this with the format specified for the DataGrid or DataList. You can specify the style attribute of the DataGrid or DataList to prevent the template from being messy. In addition, you can use some tools to automatically set the style attributes of the DataGrid and DataList, such as Microsoft Visual Studio. NET or ASP. NET Web Matrix.
In addition to extended development time, Repeater also lacks built-in features that help support paging, editing, or data editing. Due to lack of support for these features, the Repeater scored very low in the availability rating. Of course, if all you are interested in is displaying data without any special ringtones or sound, the lack of Repeater functions is not a major drawback. I emphasize the word "if" because, in general, once a Web application is deployed, users will find that they need additional features, such as sorting, paging, and editing.
It is not surprising that Repeater has a complementary quality), that is, performance. The Repeater has better performance than DataList, and better performance than DataGrid. Figure 3 shows the number of requests that Repeater can process per second and compares them with DataGrid and DataList.
Figure 3: Repeater requests per second
- Getting started with DataList controls
- Exploring the operation mechanism of the DataGrid Web Control
- Discuss the similarity between ASP. NET data Web controls
- Transformation from traditional ASP to ASP. NET: Understanding controls
- How to use ASP. NET to debug APIs