How to change the default sort order to descending?

发布于 2022-09-06 08:56:00 字数 501 浏览 34 评论 0

How do I change the defaultSort of my webGrid to be in the opposite/descending order? If it were SQL, I'd be adding a DESC somewhere. Here's my working line of code for an Ascending sort:

var grid = new WebGrid(dq, rowsPerPage: 50, defaultSort: "UWDate", ajaxUpdateContainerId: "grid" );

It correctly sorts on the UWDate column in Ascending order, but I would like it to sort the opposite/descending order.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南城旧梦 2022-09-13 08:56:00

Another option is after your grid initialization:

    grid.SortDirection = SortDirection.Descending;
雾里花 2022-09-13 08:56:00

You can change the sort order within the WebGrid initialiser by putting a space followed by DESC within the defaultSort parameter string.

var grid = new WebGrid(Model, defaultSort: "UWDate DESC" ... );

Source: http://forums.asp.net/post/4962796.aspx

萌面超妹 2022-09-13 08:56:00

If you are using entity framework then you can use this syntax for ordering to descending order.

WebGrid grid = new WebGrid(Model.OrderByDescending(o=>o.Id),canPage: true);

This is the design view syntax for the grid print of the model.

@grid.Gethtml()
伴我心暖 2022-09-13 08:56:00
@{

    WebGrid grid = new WebGrid(Model, null, null, 10, true, true, ajaxUpdateContainerId: "container-grid2");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文