DataGrid's practice

zhaozj2021-02-16  57

In the ASP.NET Forum for 9CBS, the use of DataGrid is the most in consultation and discussion. This paper describes the practice of using DataGrid using the small chicken shooter. 1. Initial use of DataGrid is amazed at its DataBinding simpleness, love to use the binding column, and set "normal item" and "alignment" in the format; database data directly displays some problems, and learns to set data format, such as Set two decimal {0: F2} 2. Light browsing is not enough, so use the button column combined with ADO.net can easily increase, delete, and edit the editing function, and learned that the unit access to edit through Item.cell. Deleting content generally requires a user to confirm, so I learned to set Attribute.Add to Control ("OnClick", "Confirm ('confirmation delete?')") 3. Single table problem is basically solved, in order to jump between different pages In again, the link column is used; it is generally dynamic content, so it is basically used to use the URL field and the URL format string, and the format string is added to the {0} represents the URL field content; 4. The display of the link column can only be specified One field content, if you want to save more, it is only for the template; in fact, the template is any control, not necessarily a link. The binding expression of the template column is used in DataBinder.eval (Container.Item, "Field"), which can be bind anything. Supplement, the DataBind expression can call the member function in the DataBind expression, so you can make any calculations on the binding data; 5. If you need more content, DataGrid's support for paging is great, allow paging a little Plus set, PageIndexchanged event code written a few words, can be; 6. It can be sorted in the table header, and it is not difficult to implement in the DataGrid: Allow sorting, set the relevant column sort Expressions, SortCommand events write a few lines of code, but also!

With the gradual understanding of ASP.NET, it is also costly: 1. Table content is more content, if viewsource in the browser, ViewState is quite large; 2. Automatic paging using DataGrid is the whole page After the data source is taken out, the amount of data is not accepted; 3. The DataGrid itself and the system overhead of DataBinder.eval are not small.

For these questions, implementation is made on some improvements: 1. EnableViewState is set to false, re-bind DataGrid in loadpagestateFromPersistencemedium (). In conjunction with the method in the article "In Business Layer Cache Object", performance will not be affected; if Bind DataGrid is used as a private method, it is also convenient to call in IF (! Ispostback) and loadpagestateFromPersistenceMedium; 2. No use DataGrid's automatic paging, and use the database in the database, and the article is analyzed in the article; conclusion is the method of using set rowcount in the database, and can achieve optimal performance in most cases; 3. DataBinder.eval performance problem The article in Bo Guest Hall also shows very clear, take into account the readability, the method of the small chicken is used (CONTAINDATAITEM AS DATAROWVIEW ).Row [ColumnName], has not pursued speed and use index. For read-only pages with large access, the REPEATER control is changed; it is nothing more than to change the HTML result from DataGrid Render to the Template in the REPEC, so the interface is completely consistent. Finally, there is no practice about Master / Detail's DataGrid, but the article is collected in alternate; additional Microsoft's improving .NET Performance and Scalability is also worth reading.

转载请注明原文地址:https://www.9cbs.com/read-19418.html

New Post(0)