快速业务通道

ASP.NET 2.0数据教程之二十五:大数据量时提高分页的效率

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-21
ASP.NET 1
       2
       3
       4
       5
       6
       7
       8
       9
       10
       11
       12
       13
       14
       15
       16
       17
       18
       19 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"
       DataSourceID="ObjectDataSource1" AllowPaging="True">
       <Columns>
      <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
       <asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
       <asp:BoundField DataField="SupplierName" HeaderText="Supplier" SortExpression="SupplierName" />
       <asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />
       <asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price"
       HtmlEncode="False" SortExpression="UnitPrice" />
       </Columns>
       </asp:GridView>
       <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
       SelectMethod="GetProductsPaged" TypeName="ProductsBLL">
       <SelectParameters>
       <asp:Parameter Name="startRowIndex" Type="Int32" />
       <asp:Parameter Name="maximumRows" Type="Int32" />
       </SelectParameters>
       </asp:ObjectDataSource>

如果你通过 浏览器浏览页面,你会发现看不到GridView .

ASP.NET 2.0数据教程之二十五:大数据量时提高分页的效率

图 15: GridView 没有被显示

由于在ObjectDataSource 里的 GetProductsPaged的startRowIndex和maximumRows的参数都为0,由SQL没有返回任 何的记录因此GridView 看不到了.

我们需要将ObjectDataSource 配置成 为自定义分页来修补上面的问题.下面的步骤可以完成这个:

将 ObjectDataSource的 EnablePaging 属性设为true – 这样表示必须传两个 参数给SelectMethod方法: 一个指定Start Row Index (StartRowIndexParameterName), 一个指定Maximum Rows (MaximumRowsParameterName).

设置O

面差不 多:

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号