源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Gridview自动排序功能的实现

  • 时间:2021-04-05 07:23 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Gridview自动排序功能的实现
[b]注意两点: [/b]1.要将gridview的AllowSorting属性置为true,同时设置OnSorting事件 2.在OnSorting事件中对排序的列设定SortExpression属性
[url=../UserLogin.aspx]                }
                ViewState["sortExpression"] = "Isdistribution";                 ViewState["sort"] = " ASC";             }             //绑定信息             BindNodeInfo();         }         public void BindNodeInfo()         {             NodeLogic log = new NodeLogic();             DataSet myset = log.GetNodeInfo();     //获取数据源             DataView myview = myset.Tables[0].DefaultView;             myview.Sort = ViewState["sortExpression"].ToString() +" "+ ViewState["sort"].ToString();             this.NodeGridView.DataSource = myview;             NodeGridView.DataKeyNames = new string[] { "node_id" };               //设置主键字段             NodeGridView.DataBind();                                                  //绑定GridView控件          }         protected void NodeGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)         {             this.NodeGridView.PageIndex = e.NewPageIndex;             BindNodeInfo();         }         protected void NodeGridView_RowDataBound(object sender, GridViewRowEventArgs e)         {             // 自动给第一列编号             if (e.Row.RowIndex > -1)             {                 e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + 1);             }         }         protected void NodeGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)         {             NodeLogic log = new NodeLogic();             int id = int.Parse(this.NodeGridView.DataKeys[e.RowIndex].Values[0].ToString());             if (log.DeleteNodeInfo(id))             {                 this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除成功!');", true);             }             else                 this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除失败!');", true);             //重新更新数据显示             BindNodeInfo();         }         protected void NodemGridView_RowEditing(object sender, GridViewEditEventArgs e)         {         }         protected void AddNode_Click(object sender, EventArgs e)         {             Response.Redirect("AddNode.aspx");         }         protected void NodeGridView_Sorting(object sender, GridViewSortEventArgs e)         {             if (ViewState["sortExpression"] != null)             {                 if (ViewState["sort"].ToString() == "Asc")                 {                     ViewState["sort"] = "Desc";                 }                 else                 {                     ViewState["sort"] = "Asc";                 }             }             BindNodeInfo();         }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部