[英]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.