加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

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

发布时间:2021-07-17 14:26:31 所属栏目:Asp教程 来源:互联网
导读:副标题#e# 当DataGrid同时具有分页和排序功能时应注意在重新绑定数据源时,MyDataGrid.CurrentPageIndex=0; 下面给实现以上功能的原码,也就不多缀了aspx中包含有DataGrid和控制其数据源变化的dropdownlist DataGrid代码 asp:datagrid runat="server" Borde

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

  }

(编辑:大连站长网)

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

热点阅读