2010-10-22 78 views
3

我有綁定到一個linqed SP這樣一個網格:排序綁定到LINQ SP一個gridview

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

可悲的是,沒有做任何排序..其實錯誤 「數據源不支持服務器端數據分頁。」

有什麼想法?

回答

4

d.GetType().GetProperty(sortExpression)返回一個PropertyInfo對象。你需要的是這樣的財產的價值:

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