Re: Sort Expression and Direction

Discussion in 'ASP .Net' started by Alexey Smirnov, Jan 23, 2009.

  1. On Jan 23, 8:09 pm, JJ297 <> wrote:
    > I have a gridview with auto generated fields.  I have the first field
    > hidden but when I click on the seceond field I want it to take the
    > sort of the first field.  I tried this but it's not doing anything.
    >
    >  Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
    > GridViewSortEventArgs)
    >
    >         If e.SortExpression = "sort" Then ' hidden field column
    >
    >             e.SortDirection = "Reg" ' Filed I want to be sort
    >         End If
    >
    >     End Sub
    >
    > What am I doing wrong?


    You need to bind the gridview again after that (e.g. GridView1.DataBind
    ())
     
    Alexey Smirnov, Jan 23, 2009
    #1
    1. Advertising

  2. On Jan 23, 8:47 pm, JJ297 <> wrote:
    > On Jan 23, 2:20 pm, Alexey Smirnov <> wrote:
    >
    >
    >
    > > On Jan 23, 8:09 pm, JJ297 <> wrote:

    >
    > > > I have a gridview with auto generated fields.  I have the first field
    > > > hidden but when I click on the seceond field I want it to take the
    > > > sort of the first field.  I tried this but it's not doing anything.

    >
    > > >  Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
    > > > GridViewSortEventArgs)

    >
    > > >         If e.SortExpression = "sort" Then ' hidden field column

    >
    > > >             e.SortDirection = "Reg" ' Filed I want to be sort
    > > >         End If

    >
    > > >     End Sub

    >
    > > > What am I doing wrong?

    >
    > > You need to bind the gridview again after that (e.g. GridView1.DataBind
    > > ())

    >
    > I added that but it's still not working.
    >
    > Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
    > GridViewSortEventArgs)
    >
    >         If e.SortExpression = "sort" Then
    >             ' original columnname
    >             e.SortExpression = "Reg"
    >         End If
    >         ' New field for sorting
    >         GridView1.DataBind()
    >
    >     End Sub
    >
    >  It's still sorting by the 2nd column
    >
    > Here's my table.  When I click on Dec08 it goes in order then when I
    > click on Reg I want it to go back into Sort field order but it
    > doesn't.
    >
    > Sort   Reg    Dec08   Jan09
    > 1      NAT    12.4    15.8
    > A      BOS    22.2    23.0
    > B      NYC    25.9    16.0
    > C      PHL    12.3    33.3
    > D      ATL    14.4    23.3


    Do you load your grid twice? Check if you have If Not Page.isPostBack
    when you load it the first time (I guess you do it in the Page_Load)
     
    Alexey Smirnov, Jan 24, 2009
    #2
    1. Advertising

  3. On Jan 26, 4:17 pm, JJ297 <> wrote:
    > On Jan 23, 7:47 pm, Alexey Smirnov <> wrote:
    >
    >
    >
    > > On Jan 23, 8:47 pm, JJ297 <> wrote:

    >
    > > > On Jan 23, 2:20 pm, Alexey Smirnov <> wrote:

    >
    > > > > On Jan 23, 8:09 pm, JJ297 <> wrote:

    >
    > > > > > I have a gridview with auto generated fields.  I have the first field
    > > > > > hidden but when I click on the seceond field I want it to take the
    > > > > > sort of the first field.  I tried this but it's not doing anything.

    >
    > > > > >  Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
    > > > > > GridViewSortEventArgs)

    >
    > > > > >         If e.SortExpression = "sort" Then ' hidden field column

    >
    > > > > >             e.SortDirection = "Reg" ' Filed I want to be sort
    > > > > >         End If

    >
    > > > > >     End Sub

    >
    > > > > > What am I doing wrong?

    >
    > > > > You need to bind the gridview again after that (e.g. GridView1.DataBind
    > > > > ())

    >
    > > > I added that but it's still not working.

    >
    > > > Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
    > > > GridViewSortEventArgs)

    >
    > > >         If e.SortExpression = "sort" Then
    > > >             ' original columnname
    > > >             e.SortExpression = "Reg"
    > > >         End If
    > > >         ' New field for sorting
    > > >         GridView1.DataBind()

    >
    > > >     End Sub

    >
    > > >  It's still sorting by the 2nd column

    >
    > > > Here's my table.  When I click on Dec08 it goes in order then when I
    > > > click on Reg I want it to go back into Sort field order but it
    > > > doesn't.

    >
    > > > Sort   Reg    Dec08   Jan09
    > > > 1      NAT    12.4    15.8
    > > > A      BOS    22.2    23.0
    > > > B      NYC    25.9    16.0
    > > > C      PHL    12.3    33.3
    > > > D      ATL    14.4    23.3

    >
    > > Do you load your grid twice? Check if you have If Not Page.isPostBack
    > > when you load it the first time (I guess you do it in the Page_Load)- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > No I don't have it ther ein the page load.  Should I put it there?


    Page_Load executes during every postback, and when you sort the grid
    it executes Page_Load and then GridView1_Sorting.
     
    Alexey Smirnov, Jan 26, 2009
    #3
    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. Efy.
    Replies:
    2
    Views:
    1,122
  2. rockdale
    Replies:
    0
    Views:
    817
    rockdale
    Jun 8, 2006
  3. ASF
    Replies:
    3
    Views:
    2,980
  4. rockdale

    Postback does not maintain sort direction Image?

    rockdale, Jun 8, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    414
    rockdale
    Jun 21, 2006
  5. Navin
    Replies:
    1
    Views:
    769
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page