What is the ASP. NET DataGrid Control: Fully templated Grid

Source: Internet
Author: User

The ASP. NET DataGrid Control presents a multi-column, fully templated grid. It is the most common and flexible control for all data binding Web controls in the. NET Framework. To some extent, the DataGrid user interface is similar to a Microsoft Excel worksheet. Although DataGrid has advanced programming interfaces and complete attribute sets, it only generates HTML tables that contain interleaved superlinks to provide interoperability functions such as sorting and paging commands ).

Using the DataGrid control, you can create a simple data binding column to display the data retrieved from the data source.) templated columns allow you to design the layout of cell content ), last but most importantly, the command-based column allows you to add specific features to the grid ).

The DataGrid Control is suitable for reporting data, and it is flexible enough to allow you to build complex and professional data tables that allow you to freely implement functions such as paging and sorting. However, other functions, such as deepening and master/detail, only require a small amount of work. In this month's column, I will discuss a feature that cannot be provided by the control itself, but is quite popular with many people. Therefore, let's take a look at how to automatically generate complex reports. In these tables, a summary row with partial aggregate must be displayed.

ASP. NET DataGrid Control

You can bind the actual data to the control instance by setting the DataSource attribute of the DataGrid Control. This attribute is of the general Object type and supports two configuration schemes. It is usually set using the data object that implements the ICollection interface. DataTable and DataView objects are usually used. Another method is to set it with another object type, such as a data reader object. However, in this case, you must enable the custom paging mechanism; otherwise, an exception occurs. To put it simply, you must either bind the DataGrid to a paging data source, that is, a set object used to implement the enumeration number) or provide Paging for yourself.

For Web controls, data binding is enabled. the user interface is refreshed only when the DataBind method is called. During the refresh process, the control traverses the data source and copies some rows to its Items collection. The Items attribute indicates the content of the currently displayed page. If the data source supports pagination (ICollection), The DataGrid selects the correct row subset from DataSource that fits the current page. Otherwise, it assumes that all the content of DataSource is suitable for the current page and all of them are loaded into Items. After filling in the Items, the user interface of the control is displayed.

What are the lessons learned here? All the content that the DataGrid Control can safely and consistently display is the rows contained in the bound data source. Therefore, if you want to insert a summary row to group some records and display partial totals by using the public key, you must specify the method to insert these summary rows directly to the data source.

However, inserting a summary row into a data source is not enough. In fact, we must be able to distinguish between summary and general, and present the former with different visual styles.

Before attaching data to the control, make sure that the data source contains all the summary rows required by the control. Next, hook the ItemCreated event, check each summary row, and draw them with different la S and styles. Let's take a look at how to insert summary rows between different SQL query rows. I will use a sample application based on the Northwind SQL Server database to explain my point of view. This application lists all orders that each customer has placed in a given year. Orders are grouped by year and customer ID. Each customer has an additional line to summarize the total and total orders.

The above describes the basic knowledge of the ASP. NET DataGrid Control.

  1. Comparison between ASP. NET's GridView and DataGrid controls
  2. . NET beginner's Guide: easily customize the DataGridView Control
  3. C # Some common operations on the DatagridView
  4. ASP.net exports the DataGrid content as an excel file
  5. Button selection event in the DataGrid

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.