Asp.Net不用控件分页

不用DataGrid控件分页功能,而且当前页显示粗体字,贴出全部代码。

  private void RptDataBinder()
    {
        //建立数据库连接
        string dbconn = ConfigurationSettings.AppSettings["dbconn"] + Server.MapPath(ConfigurationSettings.AppSettings["dbpath"]);
        OleDbConnection conn = new OleDbConnection(dbconn);
        conn.Open();
        //读取数据
        OleDbCommand cmd = new OleDbCommand("select * from download order by did desc", conn);
        OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        oda.Fill(ds);
        //利用分页控件 PageDataSource
        int curPage = Convert.ToInt32(Request.QueryString["page"]);  //获取当前页数
        int AllPage;  //定义页面
        System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
        if (curPage <= 0)
        {
            curPage = 1;
        }
        RecordCount = ds.Tables[0].Rows.Count;
        ps.DataSource = ds.Tables[0].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = 6;
        AllPage = ps.PageCount;
        if (curPage > AllPage)
        {
            curPage = 1;
        }
        ps.CurrentPageIndex = curPage - 1;
        this.Rptdownload.DataSource = ps;
        this.Rptdownload.DataBind();
        for (int i = 1; i <= ps.PageCount; i++)
        {
            string pi;
            if (curPage == i)
            {
                pi = "<font color=#000000><b>" + i + "</b></font>";
            }
            else
            {
                pi = i.ToString();
            }
            this.PageC = this.PageC + "<font color=#333333><a href=download.aspx?page=" + i + ">" + pi + "</a></font>&nbsp;";
        }
        conn.Close();
    }

  然后在Page_Load 中调用此方法。
    this.RptDataBinder(); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值