In-depth research on Repeater controls: Maximum Flexibility

Source: Internet
Author: User

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:

 
 
  1. < asp:Repeater runat="server" id="rptEmployees"> 
  2.   < HeaderTemplate> 
  3.     < ul> 
  4.   < /HeaderTemplate> 
  5.   < ItemTemplate> 
  6.     < li>< %# DataBinder.Eval(Container.DataItem, "EmployeeName") %>< /li> 
  7.   < /ItemTemplate> 
  8.   < FooterTemplate> 
  9.     < /ul> 
  10.   < /FooterTemplate> 
  11. < /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:

 
 
  1. < ItemTemplate> 
  2.   < li>< b>< %# DataBinder.Eval(Container.DataItem, "EmployeeName")  
  3.     %>< /b>< /li> 
  4. < /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

  1. Getting started with DataList controls
  2. Exploring the operation mechanism of the DataGrid Web Control
  3. Discuss the similarity between ASP. NET data Web controls
  4. Transformation from traditional ASP to ASP. NET: Understanding controls
  5. How to use ASP. NET to debug APIs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.