AspNetPager是第三方控件,下載地址:http://www.webdiyer.com/AspNetPagerDocs/index.html。
然后通過Visaul Studio 2005的“選擇項(xiàng)”把下載后的控件DLL加載到我們的控件工具箱中。
<asp: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="首頁"
PrevPageText="上一頁" TextAfterPageIndexBox="頁" TextBeforePageIndexBox ="轉(zhuǎn)到" SubmitButtonText="Go" ShowPageIndexBox ="Always" LastPageText="尾頁" NextPageText="下一頁" ShowCustomInfoSection="Left" CustomInfoHTML="當(dāng)前%CurrentPageIndex%頁,共有%PageCount%頁"
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 = 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();
}
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇