newbie: sorting gridview!

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?
 
C

Cowboy \(Gregory A. Beamer\)

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! |
*************************************************
 
J

Jeff

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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top