• SharePoint GridView 排序 表头有图标


    代码如下:

      #region GridView1 Setting
            this.GridView1.PageIndexChanging += new GridViewPageEventHandler(GridView1_PageIndexChanging);
            this.GridView1.Sorting += new GridViewSortEventHandler(GridView1_Sorting);
            this.GridView1.RowCreated += new GridViewRowEventHandler(GridView1_RowCreated);
    
            this.GridView1.PagerTemplate = null;
            this.GridView1.AutoGenerateColumns = false;
            this.GridView1.EnableViewState = false;
            //排序
            this.GridView1.AllowSorting = true;
            //分页
            this.GridView1.AllowPaging = true;
            this.GridView1.PageSize = PageSize;
    
            #endregion
     #region GridView1 Method
        void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            GridView senderGridView = (GridView)sender;
    
            if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
            {
                foreach (TableCell cell in e.Row.Cells)
                {
                    if (cell.HasControls())
                    {
                        LinkButton button = cell.Controls[0] as LinkButton;
                        if (button != null)
                        {
                            Image image = new Image();
                            image.ImageUrl = "/_layouts/images/blank.gif";
                            if (ConvertNULL(ViewState["SortExpression11"]) == button.CommandArgument)
                            {
                                if (ConvertNULL(ViewState["SortDirection11"]) == SortDirection.Ascending.ToString())
                                    image.ImageUrl = "/_layouts/images/sortup.gif";
                                else
                                    image.ImageUrl = "/_layouts/images/sortdown.gif";
                            }
                            cell.Controls.Add(image);
                        }
                    }
                }
            }
        }
    
        void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            ViewState["SortExpression11"] = e.SortExpression;
            switch (ConvertNULL(ViewState["SortDirection11"]))
            {
                case "Ascending":
                    ViewState["SortDirection11"] = SortDirection.Descending.ToString();
                    break;
                case "Descending":
                    ViewState["SortDirection11"] = SortDirection.Ascending.ToString();
                    break;
                default:
                    ViewState["SortDirection11"] = e.SortDirection;
                    break;
            }
    
            dt11 = ViewState["DT11"] as DataTable;
            if (dt11 != null)
            {
                if (ConvertNULL(ViewState["SortDirection11"]) == SortDirection.Ascending.ToString())
                {
                    dt11.DefaultView.Sort = e.SortExpression + " asc";
                }
                else
                {
                    dt11.DefaultView.Sort = e.SortExpression + " desc";
                }
                ViewState["DT11"] = dt11.DefaultView.ToTable();
    
                this.GridView1.DataSource = dt11.DefaultView;
                this.GridView1.DataBind();
            }
        }
    
    
        void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            this.GridView1.DataSource = ViewState["DT11"] as DataTable;
            this.GridView1.DataBind();
        }
    
        #endregion
  • 相关阅读:
    Linux 下 Lua 与 LuaSQL 模块安装
    js学习笔记27----键盘事件
    js学习笔记26----事件冒泡,事件捕获
    js学习笔记25----Event对象
    js学习笔记24----焦点事件
    js学习笔记23----窗口尺寸及窗口事件
    js学习笔记22----BOM属性和方法
    VS Code 常用快捷键
    你不知道的JavaScript学习笔记1——作用域
    三种CSS方法实现loadingh点点点的效果
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2777083.html
Copyright © 2020-2023  润新知