In-depth research on ASP. NET DataGrid controls

Source: Internet
Author: User
First, we will start with a demonstration. In this demonstration, I will use a button to click the data in the event sorting table. Next we will introduce a set of attributes -- hyperlinkcolumn, bottoncolumn, and boundcolumn. These attributes can be used to add interesting custom functions for the DataGrid.

Next we will start from the last ending point -- listing. In listingCode.


DataGrid output

Note that the first change is that the column name in the header is clickable now. Run this example by yourself and you will find that the data is automatically sorted when you click on each field.

Now let's take a look at the code that causes this change. First, I will introduce the strsortby variable, which is used to store the name of the sorting parameter. The page_load () function has also been changed: When the page is loaded for the first time, the ID field is selected as the default sorting parameter.

Next, create an instance of the dataview object to change the order during running. If you set this attribute to the column to be sorted, dataview will complete the sorting for us.

Finally, use some new attributes of the initird control to bond these items together. Allowsorting activates sorting, while the onsortcommand attribute specifies the event processor to be called when receiving a sorting request. The second property has been set to dgsuperheroes_sort (). This function will be automatically called by the. NET compiler when we click the field name in the header. In this function, the sortexpression attribute stores the field names selected as sorting parameters, and then binds the DataGrid based on this field to implement sorting.

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.