Sorting information in the Gridview (ASP.NET 2.0)

When a user clicks a column name on my gridview it automatically sorts all of the information by that column name.  It works great, but I want an image of an arrow pointing up or down based on if the search is ascending or descending.  I have two images: asc.gif, des.gif - how can I get the proper one to the right of the column name based on the column which was sorted?

Thank you,

Lee
mitztraykrayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

valkyrie_ncCommented:
You may need to add them via the code-behind:

myGridView.Columns[0].HeaderText = "ColName <img src='images/asc.gif' border='0' width='16' height='16' />";

You can vary the value of HeaderText in your SortCommand function.


hth

valkyrie_nc

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mitztraykrayAuthor Commented:
valkyrie -

What method would I put this in?  The DataBound event, so it only fires once when the grid is loaded?

Thank you,

Lee
Jason ScolaroCommented:
Hi mitztraykray,

I was poking around and found this solution... seems pretty nice (and global).
http://www.dotnetjunkies.com/WebLog/thomasswilliams/archive/2005/11/09/133667.aspx

-- Jason
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

valkyrie_ncCommented:
Good question. :)  I'd say yes, put it in your DataBound.  You can put the sort value in a Session var & alter the up/down image according to that value.

Jason's solution sounds cool, too.

hth

valkyrie_nc
mitztraykrayAuthor Commented:
Thanks guys - I now have enough to go in the right direction. :)

Lee
Jason ScolaroCommented:
I liked this question, so I started trying to put together some code of my own that looped through the Columns collection and matched the Column with the SortExpression... and then I decided... this is no fun, someone else must have done this before... and sure enough... it appears someone has... ;)

-- Jason
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.