【发布时间】:2010-10-15 19:55:57
【问题描述】:
我有办法
private void BindGrid()
{
dataContext = new VTCEntities();
string SortExpression = "DisplayName";
string SortDirection = "ASC";
int skip = 0;
if (this.ViewState["SortExp"] != null)
{
SortExpression = this.ViewState["SortExp"].ToString();
}
if (this.ViewState["SortOrder"] != null)
{
string d = this.ViewState["SortOrder"].ToString();
if (d == "ASC")
{
SortDirection = "ASC";
}
else
{
SortDirection = "DESC";
}
}
if (CurrentPage != 0)
{
skip = CurrentPage * PageSize;
}
if (SortDirection == "ASC")
{
this.grdCustomers.DataSource = dataContext.CustomerSet.OrderBy(i => i.DisplayName).Skip(skip).Take(PageSize);
}
else
{
this.grdCustomers.DataSource = dataContext.CustomerSet.OrderByDescending(i => i.DisplayName).Skip(skip).Take(PageSize);
}
this.grdCustomers.DataBind();
}
它开始闻起来了,不好。我有 4 列需要排序。我想避免进行切换或其他操作来确定我要订购的 CustomerSet 上的哪个属性。一个更好的程序员如何将 SortExpression(一个字符串)关联到我的 CustomerSet 对象之一的属性?
一如既往的感谢。
吉姆
【问题讨论】:
标签: asp.net entity-framework gridview