Click here to Skip to main content
15,035,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a gridview which is connected to a database in which I have a date column with "date" as the datatype. Now I want to create custom button to sort the gridview by the date and another button to sort it by the name. I don't want to use the "Enable Sorting" from gridview because I don't want to show the date in my gridview.
Posted
Comments
[no name] 28-Sep-13 14:13pm
   
Okay.... and....? Did you maybe have some sort a question? Did you have some sort of a problem?
Rohit 2247 28-Sep-13 16:54pm
   
I think I just told you what type of problem I have. To sort columns using a button is it that hard to understand that.
Maciej Los 28-Sep-13 17:09pm
   
Yes, it is. Because of this part of your statement: I don't want to show the date in my gridview.
Rohit 2247 29-Sep-13 3:22am
   
What I am trying to say is, I am entering dates in my database but I don't want to show them to the client.
Homero Rivera 28-Sep-13 17:10pm
   
Where would such button be located?
Rohit 2247 29-Sep-13 3:22am
   
Any where on the page.

1 solution

Hello Rohit,

Its not very complicated.

Just place the buttons on the page for the Date and Name Columns and in the OnClick event of those buttons pass the sort expression with the specified column name to your stored procedure and bind the ListView again.
e.g. for Date you pass "Date" for ascending sort and "Date Desc" for descending sort.

and in your stored procedure you specify the Order By clause conditionally using Case statement.

You'll also need to keep a record of what kind of sorting is currently being used so you can use a HiddenField or any other way, its simple.

If you have trouble with the stored procedure side please post your current Store Procedure, I'll take a look.

Hope it helps.

Good luck

Azee...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900