Aspnetpager is a third party control, download address: http://www.webdiyer.com/AspNetPagerDocs/index.html.
The downloaded control DLL is then loaded into our control Toolbox through Visaul Studio 2005 's "Select Items".
<asp Tutorial: GridView id= "GridView1" runat= "Server" autogeneratecolumns= "False" >
<Columns>
<asp:boundfield datafield= "CustomerID" headertext= "CustomerID"/>
<asp:boundfield datafield= "CompanyName" headertext= "CompanyName"/>
<asp:boundfield datafield= "ContactName" headertext= "ContactName"/>
<asp:boundfield datafield= "ContactTitle" headertext= "ContactTitle"/>
<asp:boundfield datafield= "Address" headertext= "Address"/>
<asp:boundfield datafield= "City" headertext= "City"/>
</Columns>
</asp:GridView>
<webdiyer:aspnetpager id= "AspNetPager1" pageindexboxtype= "DropDownList" custominfotextalign= "left" firstpagetext= "Home"
prevpagetext= "Previous page" textafterpageindexbox= "page" Textbeforepageindexbox = "Go to" submitbuttontext= "went" Showpageindexbox = " Always "lastpagetext=" last "nextpagetext=" Next "showcustominfosection=" left "custominfohtml=" current%currentpageindex% page, total %pagecount% page "
runat= "Server" onpagechanging= "aspnetpager1_pagechanging" >
</webdiyer:AspNetPager>
</div>
///
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Bind ();
}
}
public void bind ()
{
OleDbConnection con = new OleDbConnection (@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:northwind.mdb");
OleDbCommand cmd = new OleDbCommand ("SELECT * from Customers", con);
OleDbDataAdapter da = new OleDbDataAdapter (cmd);
DataSet ds = new DataSet ();
Da. Fill (DS);
Aspnetpager1.recordcount = ds. Tables[0]. Rows.Count;
PagedDataSource PS Tutorial = new PagedDataSource ();
Ps. AllowPaging = true;
Ps. CurrentPageIndex = this. Aspnetpager1.currentpageindex-1;
Ps. DataSource = ds. Tables[0]. DefaultView;
This. Gridview1.datasource = PS;
This. Gridview1.databind ();
}
protected void Aspnetpager1_pagechanging (Object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
This. Aspnetpager1.currentpageindex = E.newpageindex;
Bind ();
}