Differences and differences between ASP. NET data Web controls

Source: Internet
Author: User

ASP. NET data Web controls are DataGrid, DataList, and Repeater. Before studying the differences, you must first understand the similarity. From a higher level perspective, the most basic similarity is that DataGrid, DataList, and Repeater are designed to perform roughly the same operation: display data. Another similarity is the code required to bind data to a data Web control. Specifically, you only need the following two lines of code:

 
 
  1. dataWebControlID.DataSource = someDataSource  
  2. dataWebControlID.DataBind()  

Usually, it is assigned to the ASP. NET data Web Control

DataSource

Attribute

SomeDataSource

The object is a DataSet, SqlDataReader, OleDbDataReader, or a set such as Array, ArrayList, or

System. Collections

Other classes in the namespace ). However, any object that implements the IEnumerable interface can be bound to a data Web control.

DataBind ()

Method Enumeration

DataSource

. For

DataSource

Each record in will create an item and append it to the Data Web Control's

Items

Collection. Each item in the Data Web control is a class instance. The specific class used for each item of the control depends on the Data Web control. For example, each item in the DataGrid is

DataGridItem

Class, and each item in Repeater is

RepeaterItem

Class.

Each data Web control uses different classes for each item, because the rendering of these items determines the HTML Tag generated by the Data Web control. For example, the DataGridItem class is from

TableRow

Class, which means that

DataGridItem

Are more or less displayed as a table row. This makes sense because the DataGrid is designed in HTML

<Table>

Data is displayed in a table in the tag.

<Table>

Each item is displayed as a single row. On the other hand, Repeater is designed to allow full customization of its output. Therefore, the RepeaterItem class is not from

TableRow

Class is not surprising.

Another similarity between ASP. NET data Web controls is that each control can use a template to provide highly customized output. The DataList and Repeater controls must use templates to specify their content, the DataGrid uses the TemplateColumn column type to select a template for a specific column. We will discuss different DataGrid column types in the next section "study the DataGrid Web control ).

The last one worth noting is that the DataGrid and DataList controls are

WebControl

Class, while the Repeater control is

Control

Class.

WebControl

Class contains many aesthetic attributes, such

BackColor

,

ForeColor

,

CssClass

,

BorderStyle

. This means that if you use the DataGrid and DataList, you can

WebControl

Class. The Repeater does not have any such style attributes.

Differences and selection of ASP. NET data Web controls

When displaying data on ASP. NET Web pages, many developers choose the data Web control they are most familiar with, usually the DataGrid. However, this blind decision is not wise, because there is no general "best" Data Web control. When deciding which data Web control to use for a given Web page, you should first consider the following issues to determine which control is most suitable for the task at hand. Do you want to allow users to sort data? You need to use non-HTML

<Table>

Is the format displayed? Will the page be accessed in large quantities, so performance is a key issue?

Because the DataGrid allows end users to sort, paging, and edit their data, the DataGrid Web Control provides the best feature set in these three data Web controls. When using the DataGrid, you only need to add it to the Web page and write several lines of code. Therefore, the DataGrid is also the most easy-to-use Data Web control. However, it is easy to use and powerful functions at a cost. For example, the performance cost: DataGrid is the most efficient among the three data Web controls, especially when it is placed in a Web form.

By using a template, DataList provides more control over the appearance of the displayed data than the DataGrid. However, using a template usually requires more development time than using the column type of the DataGrid. DataList also supports inline data editing, but it requires more work than the DataGrid. Unfortunately, it is not easy to provide paging and sorting support in DataList. DataList provides better performance than DataGrid, making up for these missing built-in functions.

Finally, the Repeater control allows complete and comprehensive control over rendered HTML tags. For Repeater, the only HTML generated is the value of the data binding statement in the template and the HTML Tag specified in the template, instead of generating "additional" HTML like the DataGrid and DataList. Because developers are required to specify the fully generated HTML Tag, the Repeater usually requires the longest development time. In addition, Repeater does not support built-in editing, sorting, or paging. However, the Repeater performance is indeed the best among the three data Web controls. Its performance can be compared with DataList, but it is much better than DataGrid.

  1. Transformation from traditional ASP to ASP. NET: Understanding controls
  2. How to use ASP. NET to debug APIs
  3. Five methods for generating HTML static pages using ASP. NET templates
  4. How to Use the ASP. NET Login Control
  5. What is ASP. net mvc and its advantages

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.