Some discussions about how to use DataGrid, datalist, or repeater (3)

Source: Internet
Author: User
[Datalist control]
As described above, the DataGrid uses tables to display data. You may need to further control the data display. For example, if you want to display data in a table, but there is not only one record per line, but multiple records. Alternatively, you do not want to use tables to display data, but only display them in a series of <span> labels.

Datalist abandons the list display data concept in the DataGrid. Instead, it uses a predefined template to customize the display. By using templates, you can use HTML tags or data binding at the same time. The data binding format here is: <% #... %>, Used to display the data records of a given entry in the data source. The following itemtemplate will display the companyName field in the Data source:

<Asp: datalist runat = "server" id = "mydatalist">

<Itemtemplate>

<% # Databinder. eval (container. dataitem, "companyName") %>

</Itemtemplate>

</ASP: datalist

By modifying the template above, we can display the companyName field as a bold character, while the contactname field is displayed under companyName in the normal format.

<Asp: datalist runat = "server" id = "mydatalist">

<Itemtemplate>

<B> <% # databinder. eval (container. dataitem, "companyName") %> </B>

<Br/>

<% # Databinder. eval (container. dataitem, "contactname") %>

</Itemtemplate>

</ASP: datalist>

For each record in the datalist data source, itemtemplate displays data in the same style by defining HTML tags. Itemtemplate also supports 6 Other templates:

· Alternatingitemtemplate

· Edititemtemplate

· Footertemplate

· Headertemplate

· Itemtemplate

· Selecteditemtemplate

· Separatortemplate

By default, datalist displays records in HTML tables. However, by setting the repeatcolumn attribute, you can set how many records are displayed in a row. Furthermore, you can even specify that the content of the datlist is not displayed in the table, but in the <span> label. This can be achieved by setting the repearlayout attribute.

By using the template, repeatcolumn, and repeatlayout attributes, it is obvious that datalist is more flexible in customizing data output styles than DataGrid, making the user interface design more friendly. Of course, we also need to make functional comparisons, such as paging, sorting, and record editing.

Datalist supports record editing through edititemindex templates, editcommand, updatecommand, and cancelcommand events. However, compared with the DataGrid, this requires more development time. There are two main reasons for this inconsistency in development time:

· The edit, update, and delete buttons can be automatically added in the DataGrid by setting editcommandcolumn. You must manually add the buttons in datalist.

· The boundcolumn Column Style of the DataGrid automatically uses the text box control to display the record editing interface. In datalist, you must use edititemtemplate to specify the editing interface.

Implementing the paging and sorting functions in datalist is the same as the record editing functions and is not very complex. These functions can be implemented through clever programming, which only takes some development time. Therefore, if you need to sort or edit data records, it is much easier to use the DataGrid than to use datalist.

Datalist has better performance than DataGrid, especially when datalist is included in form. Figure 2 shows the wast test on datalist.

Figure 2: Number of requests to datalist per second
It can be seen that the performance of datalist is significantly better than that of DataGrid when it is included by web form.

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.