asp.net的GridView控件使用大全_[Asp.Net教程]
GridView控件是asp.net开发中经常用到的控件之一,本网页设计教程详细介绍GridView的使用方法。 
前台.aspx
     
|<  
<  
>  
>|  
      OnSelectedIndexChanged="ddlPage_SelectedIndexChanged"> 
      10 
     15 
      20 
      30 
  后台  #region分页
protected void BindFollowExamInfoGridView(int PersonID) 
  { 
    int currentpage = Convert.ToInt32(lblPage.Text); 
    DataTable dt = new DataTable(); 
    dt = feibf.GetByPersonIDFollowExamInfo(PersonID);  //查询指定人的随访信息记录 
    if (dt.Rows.Count > 0) 
    { 
      FollowExamInfoGridView.DataSource = dt; 
      FollowExamInfoGridView.DataBind(); 
      PagedDataSource ps = new PagedDataSource(); 
      ps.DataSource = dt.DefaultView; 
      ps.AllowPaging = true; 
      ps.PageSize = Convert.ToInt32(ddlPage.SelectedValue); 
      lblPageCount.Text = ps.PageCount.ToString(); 
      this.lblPreButton.Enabled = true; 
      this.lblNextButton.Enabled = true; 
      ps.CurrentPageIndex = currentpage - 1; 
      if (currentpage == 1) 
      { 
        this.lblPreButton.Enabled = false; 
        this.lblFirstButton.Enabled = false; 
      } 
      else 
      { 
        this.lblPreButton.Enabled = true; 
        this.lblFirstButton.Enabled = true; 
      } 
      if (currentpage == ps.PageCount) 
      { 
        this.lblNextButton.Enabled = false; 
        this.lblLastButton.Enabled = false; 
      } 
      else 
      { 
        this.lblNextButton.Enabled = true; 
        this.lblLastButton.Enabled = true; 
      } 
      FollowExamInfoGridView.DataSource = ps; 
      FollowExamInfoGridView.DataBind(); 
    }      
  } 
  protected void lblPreButton_Click(object sender, EventArgs e) 
  { 
    this.lblPage.Text = Convert.ToString(Convert.ToUInt32(lblPage.Text) - 1); 
    BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"])); 
  } 
  protected void lblNextButton_Click(object sender, EventArgs e) 
  { 
    this.lblPage.Text = Convert.ToString(Convert.ToUInt32(lblPage.Text) + 1); 
    BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"])); 
  } 
  protected void lblFirstButton_Click(object sender, EventArgs e) 
  { 
    this.lblPage.Text = "1"; 
    BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"])); 
  } 
  protected void lblLastButton_Click(object sender, EventArgs e) 
  { 
    this.lblPage.Text = lblPageCount.Text; 
    BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"])); 
  } 
  protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e) 
  { 
    lblPage.Text = "1"; 
    BindFollowExamInfoGridView(Convert.ToInt32(Request.QueryString["PersonID"])); 
  } 
#endregion