The following is the key code of the paging control. The disadvantage of this Code is that the query statement is limited.
Private datatable binddatatable (INT pagenum)
{
Sqlstring = "select corpnum, nickname, corpname, ownername, address, phonenum, username, modifytime, corpcount, carcount, drivercount from tbconfigurationinfo order by modifytime ";
This. labelpagenum. Text = pagenum. tostring ();
Int page_num = convert. toint32 (this. labelpagenum. Text );
Page_counttotal = sqlhelp. getpagecount (sqlstring );
Datatable = sqlhelp. getdatatable (sqlstring, page_num, pagesize, page_counttotal );
Int pagecount = getpagecount (page_counttotal );
This. labelpagecount. Text = pagecount. tostring ();
Return datatable;
}
Private int getpagecount (INT page_count)
{
Int num = 0;
Int totalnum = page_count;
If (totalnum % pagesize = 0)
{
Num = totalnum/pagesize;
}
Else
{
Num = totalnum/pagesize + 1;
}
Return num;
}
Protected void btnnext_click (Object sender, eventargs E)
{
Txtboxturn. Text = "";
Int num = convert. toint32 (this. labelpagenum. Text) + 1;
If (Num <= convert. toint32 (this. labelpagecount. Text ))
{
Datatable dt = binddatatable (Num );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. gridview1.datasource = DT;
This. gridview1.databind ();
}
}
}
Protected void btnturn_click (Object sender, eventargs E)
{
Int num = convert.toint32(this.txt boxturn. Text );
If (Num <= convert. toint32 (this. labelpagecount. Text ))
{
Datatable dt = binddatatable (Num );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. gridview1.datasource = DT;
This. gridview1.databind ();
}
}
}
Protected void btnpre_click (Object sender, eventargs E)
{
Txtboxturn. Text = "";
Int num = convert. toint32 (this. labelpagenum. Text)-1;
If (Num> = 1)
{
Datatable dt = binddatatable (Num );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. gridview1.datasource = DT;
This. gridview1.databind ();
}
}
}
Protected void btnfirst_click (Object sender, eventargs E)
{
Txtboxturn. Text = "";
Int num = 1;
Datatable dt = binddatatable (Num );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. gridview1.datasource = DT;
This. gridview1.databind ();
}
}
Protected void btnlast_click (Object sender, eventargs E)
{
Txtboxturn. Text = "";
Int num = convert. toint32 (this. labelpagecount. Text );
Datatable dt = binddatatable (Num );
If (DT! = NULL & DT. Rows. Count> 0)
{
This. gridview1.datasource = DT;
This. gridview1.databind ();
}
}
Public static datatable getdatatable (string STR, int pagenum, int pagesize, int page_totalcount)
{
String page_numfrom = "";
If (pagenum> (page_totalcount/pagesize ))
{
Int I = page_totalcount % pagesize;
Page_numfrom = I. tostring ();
}
Else
{
Page_numfrom = pagesize. tostring ();
}
Int page_numto = pagenum * pagesize;
String page_numto = page_numto.tostring ();
String str_select = Str. Replace ("select ","");
String strreplacefrom = Str. tolower (). Replace ("from ","/");
String [] str_out = strreplacefrom. Split ('/');
String strreplaceorder = Str. tolower (). Replace ("order ","/");
String [] str_order = strreplaceorder. Split ('/');
String str_order_true = str_order [1];
String str_outtrue = str_out [0];
Str_outtrue = str_outtrue.replace ("select ","");
String str_select_out = str_select.replace ("from ","/");
String [] str_select_array = str_select_out.split ('/');
String str_select_first = str_select_array [0];
String str_last = "select top"
+ Page_numfrom + str_select_first
+ "From (" + "select top" + page_numto
+ Str_select + ")" + "as derivedtbl_1 order"
+ Str_order_true + "DESC ";
Dataset DS = getdatset_string (str_last, connstring );
Datatable = Ds. Tables [0];
Return datatable;
}