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

Discussion in 'ASP .Net' started by Arjen, Aug 16, 2005.

  1. Arjen

    Arjen Guest

    Hi,

    I get this error message when sorting a gridview:
    The GridView 'GridView1' fired event Sorting which wasn't handled

    What do I need to do?

    Thanks!
     
    Arjen, Aug 16, 2005
    #1
    1. Advertising

  2. Arjen

    Teemu Keiski Guest

    Hi,

    you have AllowSorting="true" set for the GridView and therefore you need to
    have event handler for its Sorting event

    <asp:GridView AllowSorting=true ID="GridView1" runat="server"
    OnSorting="GridView1_Sorting">
    ...
    </asp:GridView>


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


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    "Arjen" <> wrote in message
    news:ddsgue$nbj$1.ov.home.nl...
    > Hi,
    >
    > I get this error message when sorting a gridview:
    > The GridView 'GridView1' fired event Sorting which wasn't handled
    >
    > What do I need to do?
    >
    > Thanks!
    >
    >
     
    Teemu Keiski, Aug 16, 2005
    #2
    1. Advertising

  3. Arjen

    Arjen Guest

    I tried, I don't get it to work.
    I don't know what to add inside the GridView1_Sorting method.

    I'm using the gridview with templatefields.

    Can you help me?

    Thanks!




    "Teemu Keiski" <> schreef in bericht
    news:...
    > Hi,
    >
    > you have AllowSorting="true" set for the GridView and therefore you need
    > to
    > have event handler for its Sorting event
    >
    > <asp:GridView AllowSorting=true ID="GridView1" runat="server"
    > OnSorting="GridView1_Sorting">
    > ...
    > </asp:GridView>
    >
    >
    > protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    > {
    > //...
    > }
    >
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    > "Arjen" <> wrote in message
    > news:ddsgue$nbj$1.ov.home.nl...
    >> Hi,
    >>
    >> I get this error message when sorting a gridview:
    >> The GridView 'GridView1' fired event Sorting which wasn't handled
    >>
    >> What do I need to do?
    >>
    >> Thanks!
    >>
    >>

    >
    >
     
    Arjen, Aug 16, 2005
    #3
  4. Arjen

    JackMcKenzie

    Joined:
    Nov 1, 2007
    Messages:
    1
    Solution

    I came across your question while seeking an answer to the exact same situation. I found a solution elsewhere ... not exactly what you were looking for you do have to create handlers but here's some nice generic ones...

    <asp:GridView ID="gridView" OnPageIndexChanging="gridView_PageIndexChanging"

    OnSorting="gridView_Sorting" runat="server" />

    private string ConvertSortDirectionToSql(SortDirection sortDireciton)
    {
    string m_SortDirection = String.Empty;

    switch (sortDirection)
    {
    case SortDirection.Ascending:
    m_SortDirection = "ASC";
    break;

    case SortDirection.Descending:
    m_SortDirection = "DESC";
    break;
    }

    return m_SortDirection
    }

    protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
    gridView.PageIndex = e.NewPageIndex;
    gridView.DataBind();
    }

    protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
    {
    DataTable m_DataTable = gridView.DataSource as DataTable;

    if (m_DataTable != null)
    {
    DataView m_DataView = new DataView(m_DataTable);
    m_DataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

    gridView.DataSource = m_DataView;
    gridView.DataBind();
    }
    }


    I had to tweak this up a bit, as gridview datasource was null ... I went back through my custom SQL build and did DataBind() again and it works !

    Good luck.
     
    JackMcKenzie, Nov 1, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S_K
    Replies:
    1
    Views:
    861
    Alexey Smirnov
    Oct 18, 2007
  2. rote
    Replies:
    0
    Views:
    1,758
  3. Vincent
    Replies:
    12
    Views:
    12,048
    Jerry Hui
    Mar 19, 2010
  4. egsdar
    Replies:
    0
    Views:
    3,107
    egsdar
    Nov 4, 2008
  5. Jason
    Replies:
    0
    Views:
    391
    Jason
    Oct 4, 2006
Loading...

Share This Page