Among the three controls, DataGrid is the most functional, but is also the least flexible control. This feature is not flexible when outputting HTML is because it is originally designed to output data in form. A pair of tags will be established in each record output, and a pair of labels are created when the value of each field is output. DataGrid contains several properties to improve their availability. For example, by setting the DataGrid's AllowSorting property is True, and add a small number of code, the DataGrid has the functionality that is sorted by different fields. In addition, setting related properties to implement paging and single record editing features more enhanced DataGRID availability. DataGrid is also quite saving time in addition to support in availability. Use the DataGrid on the web page to display data only two lines of code. One way is used to set the data source (DataSource) bound to the DataGrid, and another is used to execute the bind command (DATABIND ()). Of course, this function is not impossible in the Repeater, just, compare with DataGrid, you need to spend a considerable amount of time and energy to implement these functions. Although DataGrid has this impressive advantage, it is also impossible to ignore it. First, as mentioned earlier, DataGrid is limited in personalized output data. Of course, you can customize fonts, colors, and line width, but it can only be HTML form. Every column in the DataGrid is an instance of the DataGridColumn class. There are five forms of DataGrid columns: • BoundColumn · ButtonColumn · EditColumn · HyperLinkColumn · TemplateColumn Each type will allow page access to interact with DataGrid in one way. For example, BoundColumn displays the field value of DataSource as plain text; HyperLinkColumn is displayed as a hyperlink. In addition, developers can customize the style of the DataGrid column by writing a custom class inherited from the DataGridColumn. Although DataGrid has so many enhanced properties, it still looks dead without flexible. This is because, no matter what the properties need to be effect on the table generated by the DataGrid. This will undoubtedly make the table bloated and lost flexibility. For example, the setting of DataGridColumn takes effect on each row of the table. This limitations of DataGrid hinders more creative display data. For example, you want every five records to be displayed in a row, or do not want to have a form to display data, you will have to give up using DataGrid. The second defect in DataGrid is its performance. In three data controls, DataGrid is the worst relative performance. ViewState generated by DataGrid will be quite large, especially when DataGrid contains more rows. Of course, you can also close the ViewState feature, but the price is that you will not be able to use sort, pagination, and record editing. In order to measure the performance of DataGrid, I use Microsoft's Web Application Stress Tool (WAST). Accurate test conditions settings and test code will be given in the end of this article. WAST will issue a request for a specific URL on the web server. Each test will continue to request a URL within a minute. WAST will represent the value of the value, which will execute the ASP.NET page in a second to the web server. In the DataList and Repeater we have to discuss and tested, we will see their performance will be better than DataGrid.
[DATALIST Control] As mentioned, DataGrid uses a table to display data. You may need to further control the display of data. For example, you want to display data in the table, but not only one record per line, but a number. Alternatively, you don't want to use the table to display the data, but only it is displayed in a series of tags. DataList Abandon the concept of listing of data in DataGrid, but uses pre-defined templates to customize the display. By using a template, you can use the HTML tag or data binding. The data binding here is: <% # ...%>, used to display a data record in the data source. The following itemTemplate will display the companyName field in the data source:
<% # DataBinder.eval (Container.DataItem, "CompanyName")%>
<% # DataBinder.eval (Container.DataItem, "CompanyName")%>
<% # Databinder.eval (container.dataitem, "contactname")%>
For each record in the DataList data source, iTemTemplate will display data in the same style by defining an HTML tag. ItemTemplate also supports other six types of other 6 templates: AlternatingItemTemplate · EditItemplate · Footertemplate · HeadeRtemplate · ItemTemplate · SelectedItemTemplate · SeparatorTemplate By default DataList will display records in the HTML table. However, by setting the RepeatColumn property, you can set how many records displayed in a row. Further, you can even specify that the content of the DatList is not displayed in the table, but the label. This can be implemented by setting the REPEARLAYOUT attribute. Through templates, RepeatColumn, and RepeatLayout properties, it is clear that DataList is more flexible than DataGrid in custom data output styles, making user interface design more friendly. Of course, we also need to perform functional comparisons, such as paging, sorting, recording editing, and more. DataList will support record editing by EditIndex Templates and EditCommand, UpdateCommand, and CancelCommand events. However, compare DataGrid, this requires more development time to achieve. There are two main reason for this development time: • Edit / Update / Remove Buttons You can add from the DataCommandColumn in the DataGrid; in Datalist, you need to be added manually. · DataGrid's BoundColumn column style automatically uses text box controls to display record editing interfaces. In DataList, you must explicitly specify what kind of editing interface for use through EditItemTemplate. Realize the paging in DataList, the sort function is the same as the record editing function, is not very complicated. These features can be implemented through clever programming, just cost some development time. So, if you need a user to sort or edit the data record, you can use DataGrid more convenient than using DataList.