Gridq sorting related to linq SP

I have a grid related to linqed SP like this:

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

when sorting, I would like it to be possible.

    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();
    }

it’s sad that it doesn’t sort at all ... actually there are errors with "The data source does not support data pumping on the server side".

any ideas?

+3
source share
1 answer

d.GetType().GetProperty(sortExpression)returns a PropertyInfo object . You need the property value:

d.GetType().GetProperty(sortExpression).GetValue(d, null);
+4
source

Source: https://habr.com/ru/post/1770886/


All Articles