Aspnetpager Pagination Control
The Aspnetpager pagination control solves many of the problems in paging, using the control directly for paging, simplifying the tedious paging work, and here is the detailed code for how I use the Aspnetpager control for paging:
1. First download the latest AspNetPager.dll to www.webdiyer.com and add the reference directly to the VS2005.
2. Register the control on the page, introduce the control, and, of course, need to use a data carrier in the page, I'm using the Repeater control.
<%=AspnetpagerNamespace""=Webdiyer
<!--Omitted-
<Webdiyer:aspnetpagerId= "AspNetPager1"Runat= "Server"HorizontalAlign= "Right"Firstpagetext= "<<"Lastpagetext= ">>"Prevpagetext= "<"NextPageText= ">" numericbuttontextformatstring= "-{0}-" width= "600px"
showcustominfosection= "left" Span style= "color: #ff0000;" > showboxthreshold= "2" pagesize= "5" inputboxclass= "Text2" textafterinputbox= "" onpagechanging< Span style= "color: #0000ff;" >= "aspnetpager1_pagechanging" />
3.cs Code
DataSet ds;
SqlDataAdapter Dr;
SqlCommand com;
ProtectedvoidPage_Load (Objectsender, EventArgs e)
{
If(!IsPostBack)
{
Stringstrconn=system.configuration.configurationmanager.connectionstrings["SperConnectionString1"]. ToString ();
SqlConnection Con=NewSqlConnection (strconn);
Con. Open ();
Com=NewSqlCommand ();
Com. Connection=Con
Com.commandtext="Select COUNT (*) from article";
Aspnetpager1.alwaysshow=True;
Aspnetpager1.pagesize=5;
Aspnetpager1.recordcount=(Int) com. ExecuteScalar ();
Con. Close ();
Repeaterdatabind ();
}
}
PrivatevoidRepeaterdatabind ()
{
Stringstrconn=system.configuration.configurationmanager.connectionstrings["SperConnectionString1"]. ToString ();
Dr=NewSqlDataAdapter ("SELECT * FROM article", strconn);
Ds=NewDataSet ();
Dr. Fill (DS, Aspnetpager1.pagesize*(Aspnetpager1.currentpageindex-1), Aspnetpager1.pagesize,"Article");
This. Repeater2.datasource=Ds. tables["Article"];
This. Repeater2.databind ();
}
ProtectedvoidAspnetpager1_pagechanging (ObjectSRC, Wuqi.Webdiyer.PageChangingEventArgs e)
{
Aspnetpager1.currentpageindex=E.newpageindex;
Repeaterdatabind ();
}
ProtectedStringFormatstring_size_13 (StringStr
{
If(str. Length> 33)
{
str = str. Substring (0, 32 ) + "" }
return&NBSP;STR;
}
4. The Pagechanging event for the last modification of the Aspnetpager control is aspnetpager1_pagechanging.
ASP. NET paging Control Library