Compare the control of the gridview and DataGrid Web Server

Source: Internet
Author: User

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.

Improved data source binding.

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
When using the DataGrid control, data sorting, paging, and local editing require additional encoding. The gridview control does not require you to write anyCodeYou can add the sorting, paging, and editing functions. 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
Generally, the dataset control, dbdatareader control, or set (such as array, arraylist, or other classes in the system. Collections namespace) are assigned to the datasource attribute of the atagrid 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
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
The DataGrid and gridview controls 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 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.

For more information about the gridview, see the gridview Web Server Control event.

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.