我的代码比个别代码要长一些,但是我的可以加查询条件,我测试了个别的代码,他们的代码如果在上面加油查询条件,不直接点击查询按钮,而是直接点击Repeater控件的“下一页”“尾页”等,会发生错误!我在这方面做了一些调整,所以代码相对要长一些:
aspx.cs文件
protected void Page_Load(object sender,EventArgs e)
{
if (!this.IsPostBack)
{
this.lblNoPage.Text = "1";
this.GridViewBind();
}
}
///<summary>
///分页代码(开始)/////////////////////////////
///</summary>
private voidGridViewBind()
{
int curPage = Convert.ToInt32(this.lblNoPage.Text.Trim());
Class1 cl = new Class1();///////////////////////////////SQL类
DataSet ds = cl.selchengshi();//////////////////////////查询语句
PagedDataSource ps = new PagedDataSource();
string totalBar = ds.Tables[0].Rows.Count.ToString().Trim();
this.lblTotalBar.Text = totalBar;
ps.DataSource = ds.Tables[0].DefaultView;
ps.AllowPaging = true;
ps.PageSize =Convert.ToInt32(this.ddlBarPage.SelectedValue.ToString().Trim());
this.lkbPrevious.Enabled = true;
this.lkbNext.Enabled = true;
this.lkbHome.Enabled = true;
this.lkbLast.Enabled = true;
ps.CurrentPageIndex = curPage - 1;
int nobar = curPage * ps.PageSize;
this.lblNoBar.Text = nobar.ToString().Trim();
if (curPage == 1)
{
this.lkbPrevious.Enabled = false;
this.lkbHome.Enabled = false;
}
if (curPage == ps.PageCount)
{
this.lkbNext.Enabled = false;