Gridview自动排序功能
来源:互联网 发布:淘宝网天猫浇花的水壶 编辑:程序博客网 时间:2024/05/23 19:16
注意两点:
1.要将gridview的AllowSorting属性置为true,同时设置OnSorting事件
2.在OnSorting事件中对排序的列设定SortExpression属性
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Session["Admin"] != "admin") { //如果会话过期,则应该重新登录 this.Response.Write(" <script language=javascript>alert('你无权访问该页面,请与管理员联系!');window.location.href='../UserLogin.aspx';</script> "); }
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(); }
- Gridview自动排序功能
- GridControl中GridView的列自动排序功能
- gridview列排序功能
- GridView自动排序
- GridView自动排序
- GridView自动排序
- GridView自动排序
- gridview自动排序示例分享-自动排序
- GridView排序功能的实现
- GridView的双向排序功能
- GridView排序功能的实现
- DEV gridview不自动排序
- gridview自定义绑定字段实现排序功能
- gridview手动添加排序功能总结
- GridView自动排序(正序、倒序)
- gridview添加一列自动增长排序字段
- GridView实现自动排序带上下箭头
- 手工实现GridView排序、删除、编辑、新增数据功能
- c++基类不为虚析构函数的一个风险
- 敏捷开发生态系统系列之四:计划跟踪II(自组织团队-开发团队自己估算-PO挑战估算-同行压力)
- WebKit内核源代码分析(二)
- Android ANR:Application Not Responding
- WebKit内核源代码分析(三)
- Gridview自动排序功能
- SQLMAP使用方法
- vxWorks中Timer相关的测试程序
- C 箴言:多态基类中将析构函数声明为虚拟
- python攻击代码
- 使用socket的Linux上的C语言文件传输顺序服务器和客户端示例程序
- ASP.NET中上传并读取Excel文件数据
- WebKit 内核源代码分析 ( 四 )
- 虚拟机与互联网