2011-05-10 59 views
4

我有一個GV手動數據綁定。但問題是,它給了我這個錯誤:Gridview事件排序不處理

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The GridView 'gvAgentList' fired event Sorting which wasn't handled.

頁面索引相同。這裏是我寫的功能,從後面的代碼中執行:

protected void gvAgentList_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     string selectedEntity; //string for Labeling in Master Page! 
     int selectIdEntity; //int for storing Plan IDs in Plan Page! 
     GridViewRow row = gvAgentList.SelectedRow; 
     selectedEntity = row.Cells[2].Text.ToString(); 
     selectIdEntity = Int16.Parse(row.Cells[1].Text.ToString()); 
     Session["EntityIdSelected"] = selectIdEntity; 
     Session["EntitySelected"] = selectedEntity; 
     Response.Redirect("~/FrontEnd/Users.aspx?EntityID=" + row.Cells[1].Text.ToString()); 
    } 

我不知道我應該在這裏使用哪個事件處理程序?它在我改變頁面索引時沒有調用這個函數!任何幫助?

回答

7

當您手動進行數據綁定時,您必須處理它周圍的所有事件。

對於排序,您應該有GridView的Sorting事件處理程序(MSDN文檔有一個很好的例子)。

<asp:GridView ID="GridView1" OnSorting="GridView1_Sorting" /> 

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) 
{ 
    ... 
} 
+0

謝謝巴拉,索引怎麼樣? – 2011-05-10 18:17:39

+2

不要忘記在你的標記中添加AllowSorting = True .. – rofans91 2012-01-03 04:15:51

+0

謝謝,我的問題 – mitchellt 2014-03-09 11:55:19

0

您可以處理JavaScript的排序事件,你或許應該刪除的排序與後端代碼處理。另外不要忘記一起刪除AllowSorting = true。

我通常實現jquery datatables前端處理,如排序和什麼不是。這是一個鏈接,讓你開始:http://www.datatables.net/