ASP.NET 2.0中的counterpager

来源:互联网 发布:算法导论第二版 编辑:程序博客网 时间:2024/05/16 19:25

ASP.NET 2.0中的counterpager,是个简单分页的轻量组件,可以指定要分页的数据源。
代码比较简单,大家一看就会了
<%@ Page Language="C#" CompileWith="Default.aspx.cs" ClassName="Default_aspx" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>
        &nbsp;<asp:DataList ID="DataList1" Runat="server" DataKeyField="CustomerID" DataSourceID="SqlDataSource1">

            <ItemTemplate>

                CompanyName:

                <asp:Label Text='<%# Eval("CompanyName") %>' Runat="server" ID="CompanyNameLabel">

                </asp:Label><br />

            </ItemTemplate>

        </asp:DataList>

        <asp:ContentPager ID="ContentPager1" Runat="server" ControlToPaginate="DataList1" ItemsPerPage="5">

        </asp:ContentPager>

        <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region] FROM [Customers]"

            ConnectionString="server=localhost;uid=sa;password=xxx;database=northwind">

        </asp:SqlDataSource>

    </div>

    </form>

</body>

</html>