newbie: sorting gridview!

Discussion in 'ASP .Net' started by Jeff, May 19, 2009.

  1. Jeff

    Jeff Guest

    hi

    asp.net 3.5

    I have a gridview showing registered users. I want this gridview to always
    sort on LastActivityDate.

    This is my code (users is a MembershipUserCollection)
    gvwUsers.DataSource = users;
    gvwUsers.DataBind();
    gvwUsers.Sort("LastActivityDate", SortDirection.Descending);


    protected void gvwUsers_Sorting(object sender, GridViewSortEventArgs e)
    {
    }

    <asp:GridView ID="gvwUsers" runat="server" Width="100%"
    AlternatingRowStyle-BackColor="#FFFBD6" AllowSorting="true"
    AutoGenerateColumns="false" OnSorting="gvwUsers_Sorting"
    DataKeyNames="UserName">

    the problem is that the girdview don't get sorted, I don't know what to
    change...

    any ideas?
     
    Jeff, May 19, 2009
    #1
    1. Advertising

  2. The way I would solve this is change the code that fills users to a result
    set that is sorted on the last activity date, rather than sorting when you
    go into the grid.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    *************************************************
    | Think outside the box! |
    *************************************************


    "Jeff" <> wrote in message
    news:...
    > hi
    >
    > asp.net 3.5
    >
    > I have a gridview showing registered users. I want this gridview to always
    > sort on LastActivityDate.
    >
    > This is my code (users is a MembershipUserCollection)
    > gvwUsers.DataSource = users;
    > gvwUsers.DataBind();
    > gvwUsers.Sort("LastActivityDate", SortDirection.Descending);
    >
    >
    > protected void gvwUsers_Sorting(object sender, GridViewSortEventArgs e)
    > {
    > }
    >
    > <asp:GridView ID="gvwUsers" runat="server" Width="100%"
    > AlternatingRowStyle-BackColor="#FFFBD6" AllowSorting="true"
    > AutoGenerateColumns="false" OnSorting="gvwUsers_Sorting"
    > DataKeyNames="UserName">
    >
    > the problem is that the girdview don't get sorted, I don't know what to
    > change...
    >
    > any ideas?
    >
     
    Cowboy \(Gregory A. Beamer\), May 19, 2009
    #2
    1. Advertising

  3. Jeff

    shawpnendu

    Joined:
    Mar 4, 2009
    Messages:
    17
    Location:
    Dhaka, Bangladesh
    Try to sort before bind the gridview.
     
    shawpnendu, May 20, 2009
    #3
  4. Jeff

    Jeff Guest

    I'm "handling" OnSortting event, I put "" around handling cause the method
    is empty. I'm not sure what to put inside it
    protected void gvwUsers_Sorting(object sender, GridViewSortEventArgs e)
    {
    }

    I've seen a few examples of sorting a gridview, but all those examples is
    about the user can select what column to sort on, but here user cannot
    select coumns to sort on. The sorting columns are set when the page loads...

    I've also put ShowHeader="true" on the gridview, I've read in a book
    (asp.net 2.0 cookbook) that that was a requirement for sorting gridviews...
    It didn't makes the gidview sort for me...

    I have not implemented OnSorted...

    I'm unsure what to put inside those 2 methods you mentioned...




    "Angel J. Hernández M." <> wrote in message
    news:...
    > Hey Jeff,
    >
    > By calling this method, two events are fired:
    > * Sorted
    > * Sorting
    >
    > Question, are you handling those events?
    >
    > Cheers,
    >
    >
    > --
    > Angel J. Hernández M
    > MCP,MCAD,MCSD,MCDBA
    > Microsoft MVP
    > http://www.ajhsis.com
    > http://msmvps.com/blogs/angelhernandez
    >
    > "Jeff" <> wrote in message
    > news:...
    >> hi
    >>
    >> asp.net 3.5
    >>
    >> I have a gridview showing registered users. I want this gridview to
    >> always sort on LastActivityDate.
    >>
    >> This is my code (users is a MembershipUserCollection)
    >> gvwUsers.DataSource = users;
    >> gvwUsers.DataBind();
    >> gvwUsers.Sort("LastActivityDate", SortDirection.Descending);
    >>
    >>
    >> protected void gvwUsers_Sorting(object sender, GridViewSortEventArgs e)
    >> {
    >> }
    >>
    >> <asp:GridView ID="gvwUsers" runat="server" Width="100%"
    >> AlternatingRowStyle-BackColor="#FFFBD6" AllowSorting="true"
    >> AutoGenerateColumns="false" OnSorting="gvwUsers_Sorting"
    >> DataKeyNames="UserName">
    >>
    >> the problem is that the girdview don't get sorted, I don't know what to
    >> change...
    >>
    >> any ideas?
    >>
     
    Jeff, May 21, 2009
    #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. Replies:
    2
    Views:
    1,438
    James Kanze
    Jul 6, 2010
  2. Jason
    Replies:
    0
    Views:
    389
    Jason
    Oct 4, 2006
  3. jobs
    Replies:
    2
    Views:
    1,603
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    476
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    161
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page