排序在Gridview ASP.Net中不起作用 [英] Sorting is not working in Gridview ASP.Net

查看:78
本文介绍了排序在Gridview ASP.Net中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



Arun。这次我在ASP.Net中有一个排序问题。对于第一次单击,降序工作正常但在第二次单击升序时不再进行。它仍然是降序。我使用Tableadapter来显示gridview内容。请查看代码并纠正我错过的地方。



  protected   void  gv1_Sorting( object  sender,GridViewSortEventArgs e)
{
字符串 sdir = e.SortDirection == SortDirection.Ascending? DESC ASC;
DataView dv = new DataView(ds2.AllocationPending(ClientLoggedIn.Text));
dv.Sort = e.SortExpression + + sdir;
gv1.DataSource = dv;
gv1.DataBind();
}





另外请解释 - 有没有其他方法可以在没有Dataview的情况下应用排序。



谢谢。

解决方案

原因是e.SortDirection总是返回Ascending .... br />
因此您需要将e.SortDirection存储在ViewState中并使用该值对数据视图进行排序...

以下是一些示例..

http://stackoverflow.com/questions/250037/gridview-sorting-sortdirection-always-ascending [ ^ ]





GridView排序 [ ^ ]

Hi All,

Its Arun. This time I have a sorting issue in ASP.Net. For the first click, descending is working fine but on the second click ascending is not taken again. Its still in the descending order. I m using Tableadapter to display the gridview content. Please review the code and correct me where I ve missed.

protected void gv1_Sorting(object sender, GridViewSortEventArgs e)
{
    string sdir = e.SortDirection == SortDirection.Ascending ? "DESC" : "ASC";
    DataView dv = new DataView(ds2.AllocationPending(ClientLoggedIn.Text));
    dv.Sort = e.SortExpression + " " + sdir;
    gv1.DataSource = dv;
    gv1.DataBind();
}



Also please explain - Is there any other way to apply sorting without Dataview.

Thank you.

解决方案

The reason is e.SortDirection always returns Ascending....
so you need to store the e.SortDirection in a ViewState and sort the dataview with that value...
Here are some samples..
http://stackoverflow.com/questions/250037/gridview-sorting-sortdirection-always-ascending[^]


GridView Sorting[^]


这篇关于排序在Gridview ASP.Net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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