开发者

sorting a gridview bound to a linq SP

开发者 https://www.devze.com 2023-01-21 16:47 出处:网络
I have a grid bound to a linqed SP thus: Session[\"results\"] = db.spGetCaseByNumberOrSurname(txtCaseNum.Text.Trim(), null).ToList();

I have a grid bound to a linqed SP thus:

Session["results"] = db.spGetCaseByNumberOrSurname(txtCaseNum.Text.Trim(), null).ToList();
gvResults.DataSource = Session["results"];

on the sorting of it, i would like to be able to do this..

    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(sortExp开发者_Python百科ression));
        }
        gvResults.DataBind();
    }

sadly that doesnt do any sorting at all..it in fact errors with "The data source does not support server-side data paging."

any ideas?


d.GetType().GetProperty(sortExpression) returns a PropertyInfo object. What you need is the value of the property like this:

d.GetType().GetProperty(sortExpression).GetValue(d, null);
0

精彩评论

暂无评论...
验证码 换一张
取 消