Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > newbie: sorting gridview!

Reply
Thread Tools

newbie: sorting gridview!

 
 
Jeff
Guest
Posts: n/a
 
      05-19-2009
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?


 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      05-19-2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>

 
Reply With Quote
 
 
 
 
shawpnendu shawpnendu is offline
Junior Member
Join Date: Mar 2009
Location: Dhaka, Bangladesh
Posts: 18
 
      05-20-2009
Try to sort before bind the gridview.
 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      05-21-2009
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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?
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting list vs sorting vector boltar2003@boltar.world C++ 2 07-06-2010 09:40 AM
fired event Sorting which wasn't handled - sorting and SelectedIndexChanged Jason ASP .Net Web Controls 0 10-04-2006 02:19 PM
How to: Windows Quick Tip - How to Force Alphabetic Sorting Silverstrand Reviews & How-To's 3 08-23-2005 08:59 AM
Message searching in Thunderbird and bookmark sorting in firefox John Coxon Firefox 2 07-13-2004 07:34 PM
sorting by multiple criterias (sub-sorting) Tom Kirchner Perl Misc 3 10-11-2003 05:16 PM



Advertisments