Repost the practice of learning the DataGrid of a chicken shooter

Source: Internet
Author: User

In the ASP. NET forum of CSDN, the use of DataGrid is the most consulted and discussed.

This article describes how to use the DataGrid for a chicken shooter.

1. when using DataGrid, we are amazed at the simplicity of DataBinding. We love to bind columns and set "common items" and "alternate items" in the format. Some problems may occur when displaying database data directly, I learned how to set the data format, such as setting two decimal places {0: F2}

2. light browsing is not enough, so you can use the button column and ADO. NET to easily add, delete, and modify the editing function. You can see that the Editing Unit is accessed through Item. Cell. Generally, you need to confirm the deletion content, so you learned to set Attribute. Add ("onclick", "confirm ('Are you sure you want to delete it? ')")

3. the single table problem is basically solved. In order to jump between different pages, link columns are used. Generally, dynamic content is used. Therefore, URL fields and URL format strings are basically used, adding {0} to the format string indicates the URL field content;

4. Only one field can be specified for display of link columns. If you want multiple fields, you only need to contact the template column. In fact, the template can be any control, not necessarily a link. The binding expression of the template column uses DataBinder. Eval (Container. Item, "Field") to bind almost any content. In addition, the DataBind expression can call member functions, so it can perform any calculation on the bound data source;

5. If the content is too large, pagination is required. The DataGrid provides great support for pagination. You can set it slightly after pagination. In the PageIndexChanged Event code, you can write a few words again;

6. some table headers can be sorted very cool, and it is not difficult to implement it in the DataGrid: after sorting is allowed, set the sorting expression of the relevant columns and write several lines of code for the sortcommand event, it is also implemented! With the gradual understanding of ASP. NET, it is easy to find that:

1. There are many tables. If viewsource is displayed in the browser, the viewstate is quite large;

2. Using the automatic pagination function of the DataGrid, all pages are taken out of the data source and then bound. The performance is unacceptable when the data volume is large;

3. The system overhead of the DataGrid and databinder. Eval is not small.

To address these problems, we have made some improvements:

1. enableviewstate is set to false, and bind the DataGrid again in loadpagestatefrompersistencemedium. Combined with the methods in the article "cache objects in business layer", the performance will not be affected. In terms of code, if you use the BIND DataGrid as the private method, if (! Ispostback) and loadpagestatefrompersistencemedium are called each time, which is also very convenient;

2. without the automatic paging of the DataGrid, but using the paging in the database, the text in codeproject is well analyzed. The conclusion is that the Set rowcount method can be used in the database to achieve optimal performance in most cases;

3. databinder. the eval performance is clearly explained in the blog. Considering the readability, the chicken shooter uses the container. dataitem as datarowview ). the row [columnname] method has not been used to speed up the index. The Repeater control is used for read-only pages with a large access volume. Instead, the HTML result of the DataGrid render is changed to the template in the repeater, so the interface is completely consistent.

Finally, the master/detail DataGrid has not been used in practice, but the articles are collected for backup. In addition, Microsoft's improving. NET performance and scalability are also worth reading.

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.