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

一步一步学习ObjectDataSource控件--自定义分页排序
具体到如下网址:
http://mqingqing123.cnblogs.com/archive/2006/04/10/371118.html

上面连接给出的是使用临时表进行分页,除此以外,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>

 

下一篇将深入ObjectDataSource,单击此处进入下一序列http://www.cnblogs.com/mqingqing123/archive/2006/04/06/368452.html

 

posted @ 2006-04-20 09:04  启明星工作室  阅读(4477)  评论(3编辑  收藏  举报