ASP.NET2.0 ObjectDataSource的使用详解(3)

GridView还支持回发分页。
 GridView 和 DetailsView 支持一种特殊的分页和排序模式,它利用客户端到服务器的回调获得新页的数据或新排序的数据。若要启用此功能,请将 EnableSortingAndPagingCallbacks 属性设置为 true。注意,执行分页或排序操作时,不需要回发该页就能检索新值(不过进行了到服务器的客户端脚本回调)。当 GridView 或 DetailsView 包含模板化字段时,此功能不受支持。当启用了此功能时,也不支持在 CommandField 中显示“Select”(选择)按钮。
下面是一个使用客户回发分页的例子,来自ASP.NET快速入门,注意需要将GridView的EnableSortingAndPagingCallbacks设置为="True"


代码如下
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=" http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Paging and Sorting Using Callbacks</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:GridView AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
        DataKeyNames="au_id" DataSourceID="SqlDataSource1" EnableSortingAndPagingCallbacks="True"
        ID="GridView1" runat="server">
        <Columns>
          <asp:BoundField DataField="au_id" HeaderText="au_id" ReadOnly="True" SortExpression="au_id" />
          <asp:BoundField DataField="au_lname" HeaderText="au_lname" SortExpression="au_lname" />
          <asp:BoundField DataField="au_fname" HeaderText="au_fname" SortExpression="au_fname" />
          <asp:BoundField DataField="state" HeaderText="state" SortExpression="state" />
        </Columns>
      </asp:GridView>
      <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:Pubs %>" ID="SqlDataSource1"
        runat="server" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]">
      </asp:SqlDataSource>
   
    </div>
    </form>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值