• PagedDataSource给repeater分页


    DataTable dt = dbObject.BothEnExamCenter.FromSql(sql.ToString()).ToTable();

    int cup = this.drpCurrentPageIndex.SelectedValue == "" ? 1 : Convert.ToInt32(this.drpCurrentPageIndex.SelectedValue);

    PagedDataSource objPage = new PagedDataSource();

    objPage.DataSource = dt.DefaultView;

    objPage.AllowPaging = true;

    objPage.PageSize = Convert.ToInt32(drpCount.SelectedValue);

    objPage.CurrentPageIndex = cup - 1;

    ViewState["PageCount"] = objPage.PageCount;

    lbPageCount.Text = "一共" + ViewState["PageCount"] + "页"; 

    //绑定当前页

    if (!IsPostBack)

                {    //drpCurrentPageIndex.Items.Clear();

         for (int i = 1; i < Convert.ToInt32(ViewState["PageCount"]) + 1; i++) 

          {    this.drpCurrentPageIndex.Items.Add(i.ToString());

                    }  

      }           

      else             {  

                   //drpCurrentPageIndex.SelectedIndex = -1;      

               drpCurrentPageIndex.Items.Clear();        

             for (int i = 1; i < Convert.ToInt32(ViewState["PageCount"]) + 1; i++)                 {     

                    this.drpCurrentPageIndex.Items.Add(i.ToString());        

             }       

          }       

          drpCurrentPageIndex.SelectedValue = cup.ToString();     

            rpQuestionLine.DataSource = objPage;    

             rpQuestionLine.DataBind();

     protected void LinkUp_Click(object sender, EventArgs e)   

          {             if (Convert.ToInt32(drpCurrentPageIndex.SelectedValue) > 1)             {

                    drpCurrentPageIndex.SelectedValue = (Convert.ToInt32(drpCurrentPageIndex.SelectedValue) - 1).ToString();                 BindrpQuestionLine();             }             else             {                 PublicObject.PageHelper.Alert(this, "已经第一页");

                }         }

     protected void LinkDown_Click(object sender, EventArgs e)         {             if (Convert.ToInt32(drpCurrentPageIndex.SelectedValue) < Convert.ToInt32(ViewState["PageCount"]))             {                 drpCurrentPageIndex.SelectedValue = (Convert.ToInt32(drpCurrentPageIndex.SelectedValue) + 1).ToString();                 BindrpQuestionLine();             }             else             {                 PublicObject.PageHelper.Alert(this, "已经到了最后一页");             }         }

     protected void drpCurrentPageIndex_SelectedIndexChanged(object sender, EventArgs e)         {             int page = Convert.ToInt32((drpCurrentPageIndex.SelectedItem.Value));             BindrpQuestionLine();         }

     protected void LinkFirst_Click(object sender, EventArgs e)         {             this.drpCurrentPageIndex.SelectedValue = "1";             BindrpQuestionLine();         }

     protected void LinkLast_Click(object sender, EventArgs e)         {             this.drpCurrentPageIndex.SelectedValue = ViewState["PageCount"].ToString();             BindrpQuestionLine();         }

    protected void drpCount_SelectedIndexChanged(object sender, EventArgs e)         {             this.drpCurrentPageIndex.SelectedValue = "1";             BindrpQuestionLine();         }

  • 相关阅读:
    Asp.Net Core 项目从 1.0.1 升级到 1.1.0 的小补丁
    C# 正则表达式小坑 -- not enough
    RK 61 键盘 Ubuntu 下键位映射修改方案
    编程急转弯
    ASP.NET Core 使用 AutoFac 注入 DbContext
    分享一个微软风格的博客园主题
    EntityFramework Core 学习笔记 —— 添加主键约束
    NYOJ 69 数的长度(数学)
    NYOJ 67 三角形面积(线代,数学)
    NYOJ 66 分数拆分
  • 原文地址:https://www.cnblogs.com/liziqiang/p/3407108.html
Copyright © 2020-2023  润新知