简体   繁体   中英

Gridview Event Sorting is not handled

I have a GV in which I am data binding it manually. But the problem is that it is giving me this err:

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

Same for the page indexing. Here is the function I wrote to do it from the code behind:

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

I DONT know which event handler should I use here? Its not calling this function when I am doing a page index change! Any help?

When you are manually doing the data binding, you have to handle all the events around it.

For sorting, you should have a handler for GridView's Sorting event (the msdn doc has a good example).

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

and

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

You could handle the sorting event with JavaScript and you probably should remove the sort handling with the backend code. Also dont forget to remove AllowSorting=true all together.

I generally implement jquery datatables for front end handling such as sorting and what not. Here is a link to get you started: http://www.datatables.net/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM