我有一个绑定到linqed SP的网格:
Session["results"] = db.spGetCaseByNumberOrSurname(txtCaseNum.Text.Trim(), null).ToList();
gvResults.DataSource = Session["results"];
关于它的分类,我希望能够做到这一点..
protected void gvResults_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression;
List<spGetCaseByNumberOrSurnameResult> data = Session["results"] as List<spGetCaseByNumberOrSurnameResult>;
if (sd == SortDirection.Ascending)
{
sd = SortDirection.Descending;
gvResults.DataSource = data.OrderBy(d => d.GetType().GetProperty(sortExpression));
}
else
{
sd = SortDirection.Ascending;
gvResults.DataSource = data.OrderByDescending(d => d.GetType().GetProperty(sortExpression));
}
gvResults.DataBind();
}
遗憾的是,根本没有任何排序......实际上是错误的
“数据源不支持服务器端数据分页。”
任何想法?
答案 0 :(得分:4)
d.GetType().GetProperty(sortExpression)
会返回PropertyInfo个对象。你需要的是这个属性的价值:
d.GetType().GetProperty(sortExpression).GetValue(d, null);