ASP. NET data paging Part 3-processing the UI rendering of the gridview with custom control

Source: Internet
Author: User
Continue the first two posts in this series, "ASP. NET data paging Article 1-explore paging principles and the row_number function of SQL Server 2005 "," ASP. NET data paging second-example download ", the third post in this series, also handles the" pagination "problem of the gridview, but the first two are processing the data retrieval problem of the database, this article deals with the problem of displaying the front-end UI of the gridview.
 
The focus of this post is that I wrote a gridview M control gridview named wizardgridview, which is directly inherited from Microsoft ASP. NET 2.0 native gridview control, the execution screen is shown in 1. In the page feed (paging) function and related information display, the shortcomings of Microsoft native gridview are enhanced.

 
Figure 1 execution screen of wizardgridview. The connected database is the orders data table of the northwind database of SQL Server 2005.
 
-------------------------------------------------
Sample Code download point of this post:
Http://files.cnblogs.com/WizardWu/080907.zip
 
(In this example, the northwind database of SQL Server 2000/2005 and IIS or VS 2005/2008 are required)
-------------------------------------------------
 
If you only want to test this custom control, you can directly use IIS or VS 2005/2008 to open the sqldatasource website in the download example. However, you must have the SQL Server 2000/2005 northwind database.

In addition, in the download example, the binder objectdatasource combines the content of the first two posts in this series with the processing of "data paging", that is, when your data table has 1 million pieces of data, according to the behaviors of Microsoft's native gridview and datasource controls, each time a user clicks the next page or page number, or clicks the field title for sorting, all 1 million pieces of data are retrieved again, this will not only waste a lot of IIS host memory, but also consume a lot of DB server system resources and network bandwidth.
 
If you want to use IIS and VS 2005/2008 to enable the objectdatasource website for the Download sample, create the stored procedure included in the sample in SQL Server 2005. With this stored procedure, when users operate the gridview, each time they want to change pages or sort, they will only go to the orders data table of the northwind database to retrieve the 10 data actually needed, then, the 10 pieces of data are returned from the DB and saved in the dataset in the IIS Memory. The data is then displayed in the front-end gridview. For detailed principles, refer to the first two posts in this series.
 
 
The displayed method of the gridview is the wizm control (a c # class) written by the versionworker, as shown in figure 2. In this objectdatasource project, the attached version contains the source code and has not been compiled into a DLL. In your own ASP. NET 2.0/3.5 project, there is a bin binder, you want to use the compiled DLL directly, you can use this post download example, sqldatasource, wizardgridview two projects in the wizardgridview. DLL.
 
 
Figure 2 the structure of the objectdatasource Project is a four-layer Bll, Dal, and dal2 architecture, And the wizm control of wizardgridview is used to process the presentation of the paging UI.
 
 
In the download example, the source code of the wizardgridview is included in objectdatasource and wizardgridview. For example, 3. If you want the programmer to customize the colors of the singular, double, and bright bars of the gridview, you can set the 93rd ~ Line 95 is commented out, as shown in the following code:

Wizardgridview. CS 93rd ~ 95 rows
// Set the color of "light bar, single series, and double series"
Protected override void onrowdatabound (system. Web. UI. webcontrols. gridviewroweventargs E)
{
// The background color is temporarily written in the following three lines, but as a result, the color cannot be customized by the programmer;
// To enable custom colors for programmers, you must annotate the following three lines, that is, change the front-end. aspx of each program to set the color in the Properties window of the gridview.
Wizard_oddrowbackcolor = system. Drawing. color. fromname ("# ffffff"); // white
Wizard_evenrowbackcolor = system. Drawing. color. fromname ("# f7f6f3"); // light blue
Wizard_mouseoverbackcolor = system. Drawing. color. fromname ("# ffff77"); // beige


Figure 3 colors that allow programmers to customize the number of rows, double rows, and bits. As for the wizardenablecustompager attribute, the default value is true, that is, this UI paging function is enabled by default.

You can also set "pager row" to be displayed above or below the gridview, or above or below; you can also set the page number to be displayed on the left, center, or right. To enable customization for programmers, you must set 477th ~ in wizardgridview. CS ~ The 478 lines are annotated, as shown in the following code. Then, in line 64th of sqlserver2005.aspx, the programmer is required to add the set value.

477th ~ in wizardgridview. CS ~ 478 rows
// Set the "page number line" to be displayed at the top or bottom of the gridview, or at the top or bottom of the page number line; set the page number to be displayed on the left, center, or right.
// If it is written here, the programmer cannot customize it from the front end. To enable the programmer to customize the location, the following two lines must be annotated.
// Pagersettings. Position = pagerposition. Top; //. topandbottom;
// Pagerstyle. horizontalalign = horizontalalign. Right; sqlserver2005.aspx's 64th rows
<Pagersettings position = "TOP"/> <pagerstyle horizontalalign = "right"/>


In addition, when a class directly inherits from ASP. NET 2.0 gridview class, this custom class (that is, the custom control gridview control) in. the intelliisense in the columns tag of aspx will be invalidated for no reason, as shown in figure 4, resulting in inconvenience in programmer development. It may be a bug in Microsoft's gridview.

The solution for this example is to add two classes, wizardboundfield and wizardtempatefield, which are directly inherited from Microsoft's native boundfield and tempatefield, but can be used in the Custom wizardgridview control, the intelliisense function in columns tag resumes normal operation, as shown in figure 4. For more information about how to write sqlserver2005.aspx and default. aspx on the objectdatasource and sqldatasource websites, see download examples.


Figure 4 after being inherited from the gridview, The intelliisense in the columns tag will expire without reason by default.


The wizardgridview control in this post. If you have any suggestions or find any bugs, please leave a message. However, due to work relations and limited time, you may not be able to correct any comments or reflected bugs immediately. Please forgive me.

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.