datagrid专栏1(分页)

来源:互联网 发布:java classpath linux 编辑:程序博客网 时间:2024/06/05 03:54

 void BindGrid()
  {
   string bclassId = this.ddlClass.SelectedValue;
   BLL.Product product = new admin.BLL.Product();
   DataSet ds = new DataSet();
   ds = product.GetProductList1(bclassId);
   this.DataGrid1.AllowPaging = true;
   this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
   this.DataGrid1.DataBind();
   this.DataGrid1.DataKeyField = "ProductId";
   this.ShowState();
           
            
  }
  void ShowState()
  {
   this.lblCurrPage.Text = "第"+Convert.ToString(this.DataGrid1.CurrentPageIndex+1)+"页";
   this.lblPageCount.Text = "共"+this.DataGrid1.PageCount+"页";

  }
  public void PageButtonClick(object sender, System.EventArgs e)
  {
   string arg = ((LinkButton)sender).CommandName.ToString();
   switch(arg)
   {
    case "next":
     if(this.DataGrid1.CurrentPageIndex<this.DataGrid1.PageCount-1)
     {
      this.DataGrid1.CurrentPageIndex +=1;
     }
     break;
    case "prior":
     if(this.DataGrid1.CurrentPageIndex>0)
     {
      this.DataGrid1.CurrentPageIndex -=1;
     }
        break;
    case "last":
     this.DataGrid1.CurrentPageIndex = this.DataGrid1.PageCount-1;
     break;
    default:
     this.DataGrid1.CurrentPageIndex = 0;
     break;
   }
   this.BindGrid();
   this.ShowState();

}