如何在asp.net中添加按钮来对gridview的数据进行排序 [英] How to add buttons to sort the data of the gridview in asp.net

查看:200
本文介绍了如何在asp.net中添加按钮来对gridview的数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,它连接到一个数据库,其中我有一个日期列,其中date作为数据类型。现在我想创建自定义按钮,按日期对gridview进行排序,另一个按钮按名称对其进行排序。我不想使用gridview中的启用排序,因为我不想在gridview中显示日期。

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.

推荐答案

Hello Rohit,



它不是很复杂。



只需在页面上放置日期和名称列的按钮即可这些按钮的OnClick事件将带有指定列名排序表达式传递给存储过程并再次绑定ListView。

eg对于日期,您通过日期进行升序排序,日期描述进行降序排序。



并在您的存储过程中指定排序依据条款有条件地使用 Case 语句。



您还需要记录当前正在使用的排序类型,以便你可以使用HiddenField或任何其他方式,它很简单。



如果您在存储过程方面遇到问题,请发布您当前的存储过程,我会带一个希望它有所帮助。



祝你好运



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


这篇关于如何在asp.net中添加按钮来对gridview的数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆