簡體   English   中英

在網格視圖中對日期排序

[英]Sorting a date in Grid View

我已經為網格視圖中的所有列提供了排序選項。 排序不適用於我的日期列。 我正在使用itemTemplate和日期作為Convert.ToDateTime(Eval(“ Effective_Date”))。ToString(“ MM / dd / yyyy”)。 代碼背后的代碼如下

    protected void ProductSearchResultGridView_OnSorting(object sender, GridViewSortEventArgs e)
    {
        DataTable sortTable = (DataTable)Session[SVDB_Resources.SearchResultGridSession];

        if (sortTable != null)
        {
            DataView sortedView = new DataView(sortTable);
            sortedView.Sort = e.SortExpression + " " + GetSortDirectionString(e.SortExpression);               
            ProductSearchResultGridView.DataSource = sortedView;
            Session["SortedView"] = sortedView;
            ProductSearchResultGridView.DataBind();
        }
    }

您無法對字符串類型進行排序-Convert.ToDateTime(Eval(“ Effective_Date”))。ToString(“ MM / dd / yyyy”)僅返回字符串。 嘗試使用日期時間,例如Convert.ToDateTime(Eval(“ Effective_Date”))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM