Cenario:
我有一个GridView绑定到一个DataSource,每列都是可排序的。
我的主要查询是这样的:ASP.Net Custom Paging(w/C#)
select a, b, c, d, e, f from table order by somedate desc
我加了过滤器的形式,我可以定义值的字段中的每一个,并获得其中的形式的结果。因此,我不得不做一个自定义排序,以便当我按字段排序时,我排序筛选的查询,而不是主要的排序。 现在我要做的自定义分页,出于同样的原因,但我不明白它的理念:我要保证我可以:
- 过滤结果
- 排序列
- 当我点击第2页上,我得到的过滤和排序结果
我不知道我必须做两页,这样我就可以绑定这个GV。我的排序方法,即工作得很好看起来像:
string condition = GetConditions(); //gets a string like " where a>1 and b>2" depending on the filter the user defines
string query = "select a, b, c, d, e, f from table ";
string direction = (e.SortDirection == SortDirection.Ascending)? "asc": "desc";
string order = " order by " + e.SortExpression + " " + direction;
UtilizadoresDataSource.SelectCommand = query + condition + order;
我从来没有做过自定义分页,我想:
GetConditions()//没有问题,这里
我怎么能找到如何GridView被排序(通过什么字段和排序顺序)?
非常感谢你
好吧,我曾考虑过这一点,但这与我在GridView中分页时如何处理数据的先入为主的观念相矛盾。我认为查询是在没有页面限制的情况下对SQL进行的,并存储在ASP端,当你分页时,它只是浏览存储的数据而不是再次查询数据库。 好吧,thanx无论如何:) – 2010-12-23 14:01:53