Scott Mitchell 的ASP.NET 2.0数据教程之二十四.分页和(18)

时间:2025-03-09

Scott Mitchell 的ASP.NET 2.0数据教程之二十四.分页和排序报表数据

和默认分页方式一样,默认排序方式从BLL中获取所有数据进行排序。在未分页或者使用默认方式分页的情况下,我们没有办法改善性能(除了缓存数据)。然而在后续教程中,我们能通过自定义分页来使排序更有效率。

When binding an ObjectDataSource to the GridView through the drop-down list in the GridView’s smart tag, each GridView field automatically has its SortExpression property assigned to the name of the data field in the ProductsRow class. For example, the ProductName BoundField’s SortExpression is set to ProductName, as shown in the following declarative markup:

如果我们通过GridView智能标签的下拉框把ObjectDataSource绑定到GridView的话,GridView的字段就会自动把SortExpression属性设置为相应的ProductsRow类。比如,ProductName BoundField的SortExpression就设置为ProductName,代码如下:

1 <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />

一个字段能通过清除SortExpression(设置为空字符串)属性来禁止排序。想象下如果我们不希望用户根据价格来排序产品,我们就可以通过在代码标签或者在字段对话框(点击GridView智能标签的Edit Columns链接)中移除UnitPrice BoundField的SortExpression属性例子实现。

图13:结果根据UnitPrice以升序进行排序

Scott Mitchell 的ASP.NET 2.0数据教程之二十四.分页和(18).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219