Comparison between ASP. NET's GridView and DataGrid controls

Source: Internet
Author: User

What are the differences between the ASP. NET GridView and the DataGrid Control? Next we will start to explain:

The GridView control is the successor control of the DataGrid Control. Similar to the DataGrid Control, the GridView control is designed to display data in HTML tables. When bound to a data source, the DataGrid and GridView controls display one row in DataSource as one row in the output table.

The DataGrid and GridView controls are derived from the WebControl class. Although the GridView control and the DataGrid Control have similar object models, compared with the DataGrid Control, the former has many new functions and advantages, including:

Richer design-time functions.

The improved data source binding function between the ASP. NET GridView and the DataGrid Control.

Automatic Sorting, paging, update, and deletion.

Other column types and column operations during design.

Custom page navigation User Interface (UI) with PagerTemplate attributes ).

The differences between the GridView control and the DataGrid control include:

Different custom pages are supported.

Different event models.

Improved Design-Time Functions of the ASP. NET GridView and DataGrid controls

When using the DataGrid control, data sorting, paging, and local editing require additional encoding. The GridView control allows you to add the sorting, paging, and editing functions without writing any code. In fact, you can set properties on the control to automatically complete these tasks and other common tasks such as data binding to the data source ).

When working in a designer such as Microsoft Visual Studio, you can use the designer feature built in the GridView control. The GridView control provides support for the smart tag panel, which provides a convenient interface for performing common tasks such as setting properties and enabling template editing.

Improved data source binding between ASP. NET GridView and DataGrid controls

Generally, the DataSet control, DbDataReader control, or a set such as Array, ArrayList, or other classes in the System. Collections namespace are assigned to the DataSource attribute of the DataGrid Control or the GridView control. The DataGrid Control and the GridView control can be bound to any object that implements the IEnumerable or IListSource interface.

The DataGrid control can be declared and bound to the performancecontrol control, but this is only applicable to data selection. Manual encoding is required for sorting, paging, updating, and deletion. The GridView control supports the performanceid attribute, which accepts any objects that implement the IDataSource interface. Therefore, you can use the data source control's sorting, paging, update, and deletion functions, such as the SqlDataSource control.

Other column types of the GridView and DataGrid controls of ASP. NET

The GridView control supports the following column types: BoundField, HyperLinkField, ButtonField, CommandField, ImageField, and CheckBoxField.

Built-in and custom paging support

The DataGrid control requires additional encoding for paging. The GridView control automatically supports pagination by setting the PagerSettings attribute. The PagerSettings attribute supports four modes: Numeric default), NextPrevious, NumericFirstLast, and nextpreviusfirstlast. The Numeric mode displays the numbered page Link instead of the "next/last" link, and the NumericFirstLast option adds the first and last page links. The PagerStyle attribute of the GridView control can be used to set the style and position of the page navigation.

In addition, you can use PagerTemplate to customize the page navigation buttons of the GridView control.

Custom pages in the GridView can be provided by the bound data source control, while the AllowCustomPaging mechanism is provided by the DataGrid Control.

Extended event model of the GridView and DataGrid controls of ASP. NET

The DataGrid and the GridView control have different event models.

The DataGrid Control can trigger a single event of an operation, while the GridView control can trigger events before and after an operation. The GridView control supports Sorting events that occur when fields are sorted. Note that this sorting event occurs before the GridView control automatically processes the sorting operation, so that you have the opportunity to check or change the SortExpression attribute, you can also Cancel this operation by setting the Cancel attribute to true on the passed event parameter.

The difference between the ASP. NET GridView and the DataGrid Control is briefly introduced here, I hope to help you understand ASP. NET's GridView AND THE DataGrid Control.

The GridView control supports Sorted events that occur after the GridView Control completes the sorting operation, so that you have the opportunity to change the sorting operation result or set its format. On the contrary, the DataGrid Control supports SortCommand events that occur when columns are sorted. Likewise, the GridView control supports RowUpdating and RowUpdated events that occur before and after update operations automatically. In contrast, the DataGrid Control supports the UpdateCommand event that occurs when you click the "Update" button on the items in the grid.

  1. Brief Analysis on naming rules of ASP. NET Programming specifications
  2. Analysis of ASP. NET programming standards and Their encoding specifications
  3. Test Specification Analysis of ASP. NET Programming specifications
  4. Introduction to the five Data Controls of ASP. NET
  5. Comparison of ASP. NET data binding controls

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.