views:

37

answers:

1

hi there

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

thanks

nat

+1  A: 

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);
Jordan