Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2005, 04:36 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting of columns in Datagrid

 I am able to allow the user to sort all 8 columns (one column at a time) of my datagrid, but only in ascending order. is there a way to allow sorting in descending order in C#? thanks in advance.

 
Old July 20th, 2005, 01:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The simplest way to do this is to store the sort order in view state inside the SortCommand. When the event fires, examine the view state item. If it's null or DESC, set it to ASC. If it's ASC, set it to DESC to switch the order.

Then where you databind your data, use the view state item to apply the order. How you sort depends on the data source you're using....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Skinlike (Equationmix) by Adult (Track 13 from the album: Resuscitation) What's This?
 
Old July 21st, 2005, 07:50 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar, this is working.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting the columns yogeshyl Excel VBA 1 December 10th, 2007 07:07 PM
Problem with sorting asp:tablecell columns rrajeshbe ASP.NET 2.0 Basics 0 June 1st, 2006 08:28 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
DataGrid Sorting spm74 ASP.NET 1.0 and 1.1 Basics 3 May 26th, 2004 08:52 AM
DataGrid Sorting Example SPRIBob BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 10 July 30th, 2003 09:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.