About Sorting values in Datagrid asp.net

asp.net Pakistan
  • 13 years ago

    The GridView 'GridView1' fired event Sorting which wasn't handled.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The GridView 'GridView1' fired event Sorting which wasn't handled.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): The GridView 'GridView1' fired event Sorting which wasn't handled.]
       System.Web.UI.WebControls.GridView.OnSorting(GridViewSortEventArgs e) +1425467
       System.Web.UI.WebControls.GridView.HandleSort(String sortExpression, SortDirection sortDirection) +76
    









  • 13 years ago

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)

    {

    lblResult.Text = "";

    string x = (string)ViewState["direction"];

    if (x == null)

    {

    e.SortDirection = SortDirection.Descending;

    e.SortExpression = e.SortExpression;

    ViewState.Add("direction", "Asc");

    ViewState.Add("columnname", e.SortExpression);

    ViewState["direction"] = "Desc";

    }

    if (x == "Desc")

    {

    e.SortDirection = SortDirection.Descending;

    e.SortExpression = e.SortExpression;

    ViewState.Add("columnname", e.SortExpression);

    ViewState["direction"] = "Asc";

    }

    if (x == "Asc")

    {

    e.SortDirection = SortDirection.Ascending;

    e.SortExpression = e.SortExpression;

    ViewState.Add("columnname", e.SortExpression);

    ViewState["direction"] = "Desc";

    }

     

    bindgridview(); -- ur function to bind gridview..

    }

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook