检查数据网格是否已排序
在datagrid Item Databound事件中,我想知道网格是否已排序或第一次加载。我知道有一个 OnSortCommand 事件,我可以在此处设置一些变量来检查网格上是否发生排序。但我想知道是否有更好的方法来检查网格是否已排序。感谢副词。为了你的帮助。
PS:我看了一下这个post 并建议检查 Request.Form["__EVENTTARGET"]
和Request.Form["__EVENTARGUMENT"]
。假设我在网格和表单上的其他服务器控件中有“x”个列,我觉得使用“x”个 If 条件并检查请求是否来自这些控件之一不是正确的方法。
In the datagrid Item Databound event, I want to know if the grid has been sorted or loading for the first time. I know there is an event OnSortCommand and I can set some variable here to check if there is a sort happening on the grid. But I want to know if there is a better way to check if the grid has been sorted. Thanks in adv. for your help.
PS: I took a look at this post and it suggests to check for Request.Form["__EVENTTARGET"]
and Request.Form["__EVENTARGUMENT"]
. Let's say I have 'x' number of columns in the grid and other server controls on the form, I feel it's not a correct way to have 'x' If conditions and check if the request is from one of those many controls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 DataGridView 已排序,则将设置其 SortedColumn 属性。
If a DataGridView is sorted, its SortedColumn property will be set.
下面是验证 DataGridView 控件列的排序顺序或检查属性 sortorder 的状态的示例。
问候
Here is an example to verify the sort order of the columns of the DataGridView control or checking the status of the property sortorder.
Regards
您链接的帖子中的建议相当不雅;)
我建议您阅读此内容,这是非常直接的示例。它使用 DataView 对数据进行排序。如果您出于某种原因想要“记住”用于对网格进行排序的最后一个排序表达式,您可以简单地将其存储在 ViewState 中,如下所示:
并根据需要在 PostBack 上检索它。
The suggestion from the post you linked is rather inelegant ;)
I suggest you read this, which as very straight forward example. It uses a DataView to sort the data. If you want to "remember" for whatever reason, the last sort expression that was used to sort the grid, you can simply store it in ViewState as so:
And retrieve it on PostBack as needed.