加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

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

发布时间:2021-07-19 20:28:41 所属栏目:Asp教程 来源:互联网
导读:DataGrid同时具有分页和排序功能及注意点

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>");

  }

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读