asp.net Repeater control detailed

Source: Internet
Author: User
Tags eval html tags
The Repeater control provides the greatest flexibility in the three ASP tutorials. NET Data Web controls: The HTML markup It renders can be specified. The DataGrid or DataList automatically contains the developer-specified content in the preset HTML markup. Unlike them, Repeater will strictly generate the specified HTML markup when rendered. Therefore, if you do not want to use HTML
< table>
or a series of
< span>
tag to display data, and you want to display the data in other ways, you must use the Repeater control.
Just like DataList, you use the Repeater control to specify the tag with the template. Repeater contains the following five templates:
AlternatingItemTemplate
FooterTemplate
HeaderTemplate
ItemTemplate
SeparatorTemplate
HeaderTemplate and FooterTemplate Specify the HTML tags that appear before and after the data that is bound to repeater. AlternatingItemTemplate and ItemTemplate Specify the repeater that is used to render the
DataSource
The HTML markup and data binding syntax for each record in. For example, suppose you want to bind a dataset that contains employee information to repeater, and one of the fields of that DataSet is
EmployeeName
。 If you want to display the list of employees as unordered tables on a 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 the DataGrid and DataList, the Repeater class is not from
WebControl
Class is derived from the. As a result, repeater lacks style attributes that are common to both DataGrid and DataList. This boils down to the fact that if you want to format the data that is displayed in repeater, you must do so in the HTML tag. For example, in the above example, if you want to display the employee's name in bold, you must change the ItemTemplate to include the HTML bold tag, as follows:
 
  
  
  1. < itemtemplate>
  2. < li>< b>< % # DataBinder.Eval (Container.DataItem, "EmployeeName ")
  3. %>< /b>< /li>
  4. < /itemtemplate>
For a DataGrid or DataList, however, by putting the control's
Itemstyle-font-bold
property is set to True, the text can be displayed in bold.
The lack of style properties for repeater controls greatly increases the time metric for development. For example, suppose you decide to display data using repeater, which needs to be displayed in bold, middle-aligned, and specific fonts with a specific background color. All of this is specified with several HTML tags, which quickly make the repeater template messy. This clutter makes it much more difficult to make changes to the skin later, especially when someone else is working on the item, and you have to see a lot of HTML syntax. Compare this to the specified format for the DataGrid or DataList. For any of these two controls, you can save the template from clutter by specifying the DataGrid or DataList style properties. In addition, you can use tools to automatically set style properties for the DataGrid and DataList, such as the Microsoft Visual Studio. NET or asp.net tutorial Web matrix.
In addition to extending the development time, repeater lacks built-in features that help support paging, editing, or data editing. Due to lack of support for these features, Repeater scored low on usability assessment. Of course, if all you're interested in is displaying the data without any fancy ringtones or whistles, then repeater's lack of functionality is not a major disadvantage. I emphasize the word "if" because, in general, once a Web application is deployed, users will find that they need additional functionality, such as sorting, paging, and editing.
Repeater has a quality to compensate (which is not surprising), that is performance. Repeater performance is slightly better than DataList performance, much better than a DataGrid. Figure 3 shows the number of requests that repeater can handle per second and contrasts with the DataGrid and DataList.
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.