星空网 > 软件开发 > ASP.net

repeater 分页显示数据

 repeater 分页显示数据

表名:ChinaStates

控件:Repeater

查询代码DA

public class ChinaStatesDA   

{

    private DataClassesDataContext Context;              // 构建LINQ

      public ChinaStatesDA()

      {

        Context = new DataClassesDataContext();

      }

 

public List<ChinaStates> Select(int nowye,int numbers) 

 // 输入当前页,页面数据条数,查询数据库信息    

    {

        return Context.ChinaStates.Skip((nowye-1)*numbers).Take(numbers).ToList();

        // .Skip    是跳过多少条数据查询  .Take查询前几条数据    

    }

 

    public int Select()      // 查询数据库有多少条数据

    {

        return Context.ChinaStates.Count();   

    }

}

Cs 代码、;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)   //  运行界面

    {

        if (!IsPostBack)

        {

            bindchinadata(1,5);         // 绑定数据①

             int count = new ChinaStatesDA().Select(); //获取数据库多少条数据   

             yeshu = (int)(Math.Ceiling(count / 5.0));

// 计算数据库一页5条数据,能显示多少页

        }

    }

    private static int yeshu;     //构建总页数类型   static 表示一直有这个值。

 

private void bindchinadata(int nowye,int numbers)    //绑定数据函数①

   nowye现在第几页,numbers每页显示数据的个数

    {

        Repeater1.DataSource = new ChinaStatesDA().Select(nowye,numbers);

        Repeater1.DataBind();  

        TextBox1.Text = nowye.ToString();

   // 调用DA中的查询函数 select 绑定到Repeater 中

// TextBox1.Text 当前的页数

    }

 

 

 

  protected void Button3_Click(object sender, EventArgs e)       // 下一页

                                                                                              

    {

        int nowye = int.Parse(TextBox1.Text);        //  构建当前页面nowye 并赋值

    

        if (yeshu!= nowye)

// 判断 当前页面 nowye 是否等于总页数 yeshu  , 不等于 从新绑定Repeater

        {

            bindchinadata(nowye + 1, 5);

        }

    }

    protected void Button2_Click(object sender, EventArgs e)        // 上一页

    {

        int nowye = int.Parse(TextBox1.Text);  //  构建当前页面nowye 并赋值

        if (nowye != 1)

// 判断 当前页面 nowye 是否等于第一页  , 不等于 从新绑定Repeater

{

            bindchinadata(nowye - 1, 5);

        }

    }

    protected void Button5_Click(object sender, EventArgs e)    // 跳转页面

    {

        int nowye = int.Parse(TextBox1.Text); //  构建当前页面nowye 并赋值

        if(nowye>0 && nowye<=yeshu)    //判断大于0小于总页数从新绑定Repeater

        {

            bindchinadata(nowye, 5);

        }

    }

    protected void Button1_Click(object sender, EventArgs e)   //首页

    {

        bindchinadata(1, 5);

    }

    protected void Button4_Click(object sender, EventArgs e) //末页

    {

        bindchinadata(yeshu, 5);

    }

}




原标题:repeater 分页显示数据

关键词:Repeater

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

2019年鞋行业在速卖通的4大发展趋势:https://www.ikjzd.com/articles/91099
亚马逊卖家影响报告:2018年销售额超过1600亿美元!:https://www.ikjzd.com/articles/91100
坐拥千亿市场的德国跨境电商平台Rakuten De:https://www.ikjzd.com/articles/91101
POD是什么,那些年入千万的POD站点!:https://www.ikjzd.com/articles/91102
亚马逊 VS Zara :一场1.5万亿美元的“时尚之争”!:https://www.ikjzd.com/articles/91103
从这3个核心要素入手,实现亚马逊高效运营:https://www.ikjzd.com/articles/91104
探讨内地人开设香港账户的可行性 :https://www.kjdsnews.com/a/1836442.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流