DataGrid同时具有分页和排序功能及注意点(2)

SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand=cmd;
    DataSet ds=new DataSet();
    da.Fill(ds,"vCO");
    Count.Text="ヒット:"+ds.Tables["vCO"].Rows.Count.ToString()+"件";
    return ds;
   }

}
  /// <summary>
  ///从DataSet中除一
  /// </summary>
  /// <param></param>
  /// <param></param>
  protected void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E)
  {
    String strID=MyDataGrid.DataKeys[(int)E.Item.ItemIndex].ToString();
    //删除操作
  }
  /// <summary>
  /// 分页操作
  /// </summary>
  /// <param></param>
  /// <param></param>
  protected void MyDataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  {
   MyDataGrid.CurrentPageIndex=e.NewPageIndex;
   BindGrid();
  }
  /// <summary>
  /// 排序
  /// </summary>
  /// <param></param>
  /// <param></param>
  protected void Sort_Grid(object sender, DataGridSortCommandEventArgs e)
  {
   DataView dv= new DataView(GetData().Tables["vCO"]);
   dv.Sort= e.SortExpression.ToString();
   MyDataGrid.DataSource=dv;
   MyDataGrid.DataBind();
  }

#region Web   override protected void OnInit(EventArgs e)
  {
   //   //
   InitializeComponent();
   base.OnInit(e);
  }

  /// <summary>  /// </summary>
  private void InitializeComponent()
  {   
   this.ddlWk.SelectedIndexChanged += new System.EventHandler(this.ddlWk_SelectedIndexChanged);
   this.Load += new System.EventHandler(this.Page_Load);

}
  #endregion

private void ddlWk_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   Session["WP"]=ddlWk.SelectedValue;
   MyDataGrid.CurrentPageIndex=0;//没有这一句,当该页码超出其他数据源的范围时会出错
   BindGrid();
   Response.Write( "<script language='javascript'>parent.menuframe.location.reload();</script>");

  }

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjfxjw.html