在gridview上排序日期限制域并不起作用

时间:2015-12-09 06:37:47

标签: sorting gridview

这是我的代码,用于在具有AllowSorting = True

的gridview上对日期边界字段进行排序
<asp:BoundField DataField="VisitDate" HeaderText="Visit Date" DataFormatString="{0:MM/dd/yyyy}" SortExpression="VisitDate"/>

 protected void grdDocuments_Sorting(object sender, GridViewSortEventArgs e)
        {

            switch (e.SortExpression)
            {
                case "VisitDate":

                    if (e.SortExpression != grdDocuments.SortExpression)
                    {
                        e.SortDirection = SortDirection.Descending;
                    }
                    break;
                default:
                    break;
            }
        }

但它没有用。

1 个答案:

答案 0 :(得分:0)

使用此给定代码或按照链接查看演示,以便在gridview的绑定字段中对日期进行排序:

string sortExpression = e.SortExpression;
        ViewState["SortExpression"] = sortExpression;

        if (GridViewSortDirection == SortDirection.Ascending)
        {
            GridViewSortDirection = SortDirection.Descending;
            SortGridView(sortExpression, DESCENDING);
        }
        else
        {
            GridViewSortDirection = SortDirection.Ascending;
            SortGridView(sortExpression, ASCENDING);
        } 

演示链接:Sorting Date Demo