tag, and many tags and values of record set fields to display. Finally, after the cycle, the developer needs to generate the end mark.
This method required by traditional ASP has a big disadvantage: it is closely integrated with the source code of the HTML content and the ASP web page. Because there is no separation code and HTML content, the content of HTML and its difficulties are changed, especially for graphics artists or web designers who do not understand programming technology or web designers. Moreover, since the code is retrieved and the content that generates its content, this integration of code and HTML content is relatively relatively large number of code.
Fortunately, ASP.NET provides three controls that display data in the ASP.NET web page is absolutely simpler than the iterative methods required for traditional ASP. These three controls are DataGrid, DataList, and Repeater, I will be called the data web control later. Perhaps if you have developed an ASP.NET web page, you will have some experience in these three controls. Typically, developers start from learning DataGrid because DataGrid uses simple and it has functions that allow data sorting, paging, and editing. However, when displays data in the ASP.NET web page, DataGrid is not always the best choice for controls.
In this article, we will study the unique characteristics of each control in these data web controls. These features give each data Web control many advantages and disadvantages. Because each data web control has some shortcomings, there is no "perfect" control available for any job. When deciding which controls you use, you must weigh the advantages and disadvantages of each of these three data web controls, and then decide which control is the most appropriate.
In order to assist in comparison, we will focus on these three measures: availability (from the angle of web accessers), development time and performance. We first quickly browse the similarity between the three data web controls. Next we will study DataGrid, then study DataList, and finally look at Repeater. For each control, we will study the functions of these controls and discuss how its functional set affects these measurements.
Back to top
Similarity between data web controls
Differences between research data web controls (these differences make them different from other controls), first look at their similarities. From a higher level of view, the most basic similarity is that DataGrid, DataList, and Repeater are designed to perform substantially the same operation: display data. Another similarity to bind data to the code required for the data web control. Specifically, only the following two lines of code: DataWebControlid.DataSource = somedatasourceDataWebControlid.Database
Typically, the SOMEDASOURCE object for DataSource properties that assigns a data web control is a DataSet, SqlDataRead, OLEDBDataReader, or a collection (such as Array, ArrayList, or System.Collections namespace). However, any object that implements the IENUMERABLE interface can be bound to the data web control.
The DATABIND () method enumerates the record in the specified DataSource. For each record in DataSource, you will create an item and append to the Items collection of the data web control. Each of the data web controls is a class instance. A particular class for each of the controls depends on the data web control. For example, each of the DataGrid is an instance of the DataGridItem class, and each item in the Repeater is an instance of the REATERITEM class.
Each data web control uses different classes for each of its presence, which determines the HTML tag generated by the data web control. For example, the DataGridItem class is derived from the TableROW class, which means that each DataGridItem is more or less presented as a table line. This makes sense, because DataGrid is designed to display data in the HTML tag, in HTML , each item is presented separately. On the other hand, Repeater is designed to allow full customization of its output. Therefore, the REPEATERITEM class is not surprising from the TableRow class.
Another similarity between the data web control is that each control can use the template to provide a highly custom output. DataList and Repeater controls must use templates to specify their content, while DataGrid can choose to use templates for specific columns through the TemplateColumn column type (we will discuss a variety of DataGrid column types in the next section "Research DataGrid Web Control).
The last thing that is worth noting is that the DataGrid and DataList controls are derived from the WebControl class, while the Repeater control is derived from the Control class. The WebControl class contains many aesthetics properties such as Backcolor, Forecolor, CssClass, BorderStyle, etc. This means that if you use DataGrid and DataList, you can specify style settings from the properties inherited from the WebControl class. Repeater does not have any such style properties. As we will be discussed in the "In-depth study Repeater" section, any visual settings for the REATER output must be specified in the Template of the Repeater.
Back to top
Research DataGrid Web Control
The DataGrid Web control is the most functional in these three data web controls, but when it is the actual HTML tag generated by the custom control, it is the least flexible. This implantation in the HTML tag is due to the DataGrid is designed to use HTML to display data in tabular form. Therefore, for each record of each bind to the DataGrid, a separate table row () is created. For each field in the record to be displayed, a separate table is created (). DataGrid provides a number of functions that greatly increase the availability of data to be displayed. For example, set the DataGrid's allowsorting property to True and add a source code, and the developer can turn a normal DataGrid into a DataGrid that can be sorted by the end user. In addition, add a little workload, developers enhance DataGrid's function to allow data paging or intraline editing of data. These features significantly enhance the availability of DataGrid.
In addition to high availability, DataGrid also provides a short development time. To start using DataGrid to display data in the ASP.NET web page, just add DataGrid to the web page and write two lines necessary code: The first line binds the data to DataGrid's DataSource, the second line calls DataGrid's DataBind () Method. Obviously, as the number of functions added to the DataGrid increases, the development time has also increased, but this is only compared to the development time and other data web controls. Suppose you should allow the data displayed by the REPEater to be sorted. The function of adding such a function is certain, but it requires significant more time and energy than the same operation with DataGrid.
Although DataGrid has good availability and development time score, this control has two inherent disadvantages. First, as mentioned earlier, DataGrid is limited to the function of customizing the presented HTML tag. Yes, you can customize the fonts, colors, and borders of the DataGrid, but the fact is still, when DataGrid displays data, the result will be an HTML , each record in the DataSource, one of them , each field corresponds to one of the .
Specifically, each column in DataGrid is a class instance that derives from the DataGridColumn class. There are five built-in DataGrid column types:
• BoundColumn • ButtonColumn • hyperlinkColumn • TemplateColumn
Each column type provides data or provides an interface that allows users to interact with DataGrid. For example, BoundColumn displays the value of the DataSource field in plain text, and HyperLinkColumn displays a hyperlink, and its text and URL section may be a DataSource field. In addition to these built-in column types, you can also create custom DataGrid column types by creating DataGridColumn classes. (For examples of creating a column for extending the BoundColumn function to restrict the number of display characters, see Creating a Custom DataGridColumn Class.)
With so many DataGrid column types, you may not understand why DataGrid's HTML tags cannot be highly customized. To know, although each DataGrid column type generates different HTMLs during rendering, each column is included in a set of | tags, each line is included in a group of | tags. Therefore, even if you can customize the HTML output of each row, the DataGrid is still presented as HTML , where each line is used , each column uses a . This restriction of DataGrid prohibits more creative data display. For example, if you want to display five records in each table, you can't use DataGrid, you must use DataList or Repeater. In addition, if you want to display data in an HTML tag except , you must unfortunately, you can't use DataGrid.
The second disadvantage of DataGrid is its performance. DataGrid is the worst performance in these three data web controls. Based on this, DataGrid - especially with DataGrids generated by many rows may be very large. If you use DataGrid just to display data, you can turn off ViewState, but you can't do this when using DataGrid sort, paging, or editing.
In order to test the performance of DataGrid, I used Microsoft's free Web Application Stress Tool (WAST). Accurate test conditions and WAST settings are listed in the final "reference setting" section in this article. In addition, the code used can also be downloaded in this article.
This Web Application Stress Tool will issue a specific URL request to the web server. For each test, I have continued to request a URL as quickly as possible within a minute. WAST reports many performance measurement standards; a measure of metrics is the number of requests per second, which indicates how many ASP.NET web pages can be performed per second.
For a simple DataGrid that only displays data, two tests have been run. Specifically, DataGrid shows four fields from the Customers table from the Northwinds database (Customers table contains a total of 91 records). The AutoGenerateColumns property of DataGrid is set to TRUE. The first test puts the DataGrid in a web form ( | | |