newbie: sorting gridview!

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

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?
 
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! |
*************************************************
 
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! |
*************************************************
 
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...
 
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...
 
Back
Top