`
LiuXiaoYong
  • 浏览: 31142 次
  • 性别: Icon_minigender_1
  • 来自: 惠州
社区版块
存档分类
最新评论

aspnetpager与datalist一起使用,dt作为数据源

    博客分类:
  • .NET
阅读更多
前台页面部分代码:
<%@ Page Language="C#" MasterPageFile="~/Common.master" AutoEventWireup="true" CodeFile="AllCategory.aspx.cs" Inherits="AllCategory" Title="" MaintainScrollPositionOnPostback="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<%@ register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>//使用aspnetpager控件要引入的命名空间
        <div class="fenye">
            <webdiyer:aspnetpager id="anp_Pager" runat="server" alwaysshow="True" firstpagetext="第一页"
                lastpagetext="最后一页" nextpagetext="下一页" onpagechanged="anp_Pager_PageChanged"
                pagesize="5" prevpagetext="上一页" showboxthreshold="2"> 
            </webdiyer:aspnetpager>
        </div>
</asp:Content>

后台部分代码:
//绑定数据
    private void DataBind()
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        dt = BookManager.SelectAllBook();
        ds.Tables.Add(dt);

        //设置分页
        anp_Pager.RecordCount = ds.Tables[0].DefaultView.Count; //记录总数
        PagedDataSource pd = new PagedDataSource();
        pd.DataSource = ds.Tables[0].DefaultView;
        pd.AllowPaging = true;      //数据源允许分页
        pd.CurrentPageIndex = anp_Pager.CurrentPageIndex - 1;   //显示当前页
        pd.PageSize = anp_Pager.PageSize;   //取控件的分页大小
        dlAllBook.DataSource = pd;
        dlAllBook.DataBind();
    }

    //分页事件
    protected void anp_Pager_PageChanged(object sender, EventArgs e)
    {
        DataBind();
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics