ASP.NET paging component learning and use - use articles

xiaoxiao2021-03-06  42

Hello everyone, this article undertakes the previous article "

ASP.NET Paging Components Studies - Teaching

".

In "ASP.NET Paging Component and Using - Teaching", we explained the entire creation process of paging components, then in this article, we mainly discuss how to use this component.

Please follow these steps:

1. Create a web application engineering.

2. Add the components generated in the last article to the toolbox. If you don't know the process of adding, please refer to the article "ASP.NET Component Programming Step By Step"

3. In the default web form page, switch to the HTML view, copy the following HTML code to the

tab.

Use examples of page controls

4, the HTML code generates a three-line form, dragging the control from the toolbox to the third line of the table.

5. Add the following code in the Private Void Page_Load (Object Sender, System.EventArgs E) Event Handle:

INT CP;

IF (this.Request.Params ["currentpage"] == null)

{

CP = 1;

}

Else

{

CP = Convert.Toint32 (this.Request.Params ["currentpage"]);

}

SqlConnection Con = New SqlConnection ("Server = Accp-lzh; UID = SA; PWD = Sasa; Database = Northwind");

SQLCommand cmd = new SQLCOMMAND ("Select * from [Order Details]", CON;

SqldataAdapter adapter = new sqldataadapter ();

Adapter.selectCommand = CMD;

DataSet DS = New DataSet ();

C.Open ();

Adapter.Fill (DS, "Table");

C. close ();

DataTable DT = New DataTable ();

DT = DS.TABLES ["Table"]; // The following setup control parameters

this.lzhpages1.allcount = dt.rows.count; / / total record

This.lzhpages1.currentpage = cp; // Current page, read from the URL

this.lzhpages1.showpages = 10; // Navigator Number

this.lzhpages1.count = 10; / / The number of records displayed per page

StringBuilder SQL = New StringBuilder ();

// The following three strings are finally combined into a complete form

String htmlheader = ""; //

tag

String htmlbody = ""; // There are several

tags in the middle, ie

String htmlfoot = ""; // tag

Sql.appendformat ("Select Top {0} * from [Order Details] Where 1 = 1 and ORDERID NOT IN (SELECT TOP {1} Orderid from [Order Details] Where 1 = 1 Order by OrderID Desc) Order by OrderID DESC" , this.lzhpages1.count, this.lzhpages1.currentpage * this.lzhpages1.count;

SQLCommand cmd1 = new sqlcommand (sql.tostring (), con);

Adapter.selectCommand = cmd1;

C.Open ();

Adapter.Fill (DS, "Table1");

C. close ();

DT = DS.TABLES ["Table1"];

htmlHeader = "

/ n ";

For (int i = 0; i

{

HTMLBODY = HTMLBODY STRING.FORMAT ("

/ n
{1} / n {2}