【发布时间】:2010-12-27 23:14:19
【问题描述】:
我已经在我的代码隐藏中实现了排序功能,它适用于单词但不适用于数字...... 例如
4,693
1,494
23
当我排序时,我得到了
> 1,494
> 23
> 4,693
所以这意味着它只是检查第一个数字....
我的排序代码是:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (IsPostBack)
{
DataTable dt = Session["TaskTable"] as DataTable;
if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
GridView1.DataSource = Session["TaskTable"];
GridView1.DataBind();
}
}
else
{
Response.Redirect("~/Reports1mod.aspx");
}
}
private string GetSortDirection(string column)
{
// By default, set the sort direction to ascending.
string sortDirection = "ASC";
// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
【问题讨论】:
-
这可能是因为表格包含字符串,而不是整数。
-
您是如何填充该字段的...您是否使用数据格式字符串填充为数字,或者您将数字转换为字符串以添加逗号,然后填充网格视图列?
标签: c# asp.net gridview sorting