你的位置:首页 > 软件开发 > ASP.net > repeater 分页显示数据

repeater 分页显示数据

发布时间:2015-04-27 00:01:30
表名:ChinaStates控件:Repeater查询代码DA:public class ChinaStatesDA { private DataClassesDataContext Context; ...

 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 (#换成@)。

可能感兴趣文章

我的浏览记录