SharePoint GridView 정렬 테이블 헤더에 아이콘이 있음

9611 단어 SharePoint
코드는 다음과 같습니다.
  #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

좋은 웹페이지 즐겨찾기