• 12.23,repeater 分页显示


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class _Default : System.Web.UI.Page
    {
    public TextDataContext context = new TextDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    if(!IsPostBack )
    {

    ////定义一个值记住当前页面时第几页
    Session["ys"] = 1;
    //int qu = (Convert.ToInt32(Session["ys"]) - 1) * 5;

    ////页面加载指定数据源
    //Repeater1.DataSource = context.Car.Skip(qu).Take(5);//跳过前多少条去前几条
    //Repeater1.DataBind();

    TiaoZhuan(1);


    Literal1.Text = "";
    }

    }

    //首页
    protected void Button2_Click(object sender, EventArgs e)
    {
    int ys = 1;
    Session["ys"] = ys;
    TiaoZhuan(ys);

    }

    //上一页
    protected void Button4_Click(object sender, EventArgs e)
    {
    Literal1.Text = "";
    int ys = Convert.ToInt32(Session["ys"]);
    //判断是否是第一页
    if (ys > 1)
    {
    ys = ys - 1;
    Session["ys"] = ys;
    TiaoZhuan(ys);
    }
    else
    {
    Literal1.Text = " <script type='text/javascript'> alert('当前已经是第一页了!') </script>";
    }

    //Label3.Text = ys.ToString();

    }

    //下一页
    protected void Button5_Click(object sender, EventArgs e)
    {
    Literal1.Text = "";
    int ys = Convert.ToInt32(Session["ys"]);
    //判断是否是最后一页


    int zys = ALLYS();

    if (ys <zys)
    {
    ys = ys + 1;
    Session["ys"] = ys;
    TiaoZhuan(ys);

    }
    else
    {
    Literal1.Text = " <script type='text/javascript'> alert('当前已经最后一页啦!') </script>";
    }


    //Label3.Text = ys + "/" + zys;

    }
    //尾页
    protected void Button1_Click(object sender, EventArgs e)
    {
    int ys = ALLYS();

    Session["ys"] = ys;
    TiaoZhuan(ys);
    }
    //跳转页面
    protected void Button3_Click(object sender, EventArgs e)
    {
    int ys=1;
    try
    {
    ys = Convert.ToInt32(TextBox1.Text);
    }
    catch(Exception)
    {
    Literal1.Text = " <script type='text/javascript'> alert('请输入页数!') </script>";
    }
    int zys=ALLYS();
    if ( 1<=ys && ys <= zys)
    {
    TiaoZhuan(ys);
    Session["ys"] = ys;
    }

    else
    {

    Literal1.Text = " <script type='text/javascript'> alert('页面超出范围!') </script>";
    }
    }

    //跳转到第几页
    public void TiaoZhuan( int ys)
    {

    int qu = (ys - 1) * 5;

    //页面加载指定数据源
    Repeater1.DataSource = context.Car.Skip(qu).Take(5);//跳过前多少条去前几条
    Repeater1.DataBind();

    int zys = ALLYS();
    Label3.Text = ys + "/" + zys;

    }
    //取总页数
    public int ALLYS()
    {

    int all = context.Car.Count();
    int zys;
    if (all % 5 == 0)
    {
    zys = all / 5;

    }
    else
    {
    zys = all / 5 + 1;

    }

    return zys;

    }

    }

  • 相关阅读:
    YUI+Ant 实现JS CSS压缩
    13.QT-QMainWindow组件使用
    12.QT4.7.4-解决WIN平台和Linux平台中文乱码,QLineEdit右击菜单中文显示
    11.QT-布局管理器(Box,Grid,Form,Stacked)
    10.QT-定时器
    9.QT-标准对话框
    8.QT-对话框(模态与非模态)
    7.QT-Qt对象间的父子关系
    6.QT-简易计算器实现(详解)
    5.QT-QString类
  • 原文地址:https://www.cnblogs.com/cf924823/p/5069005.html
Copyright © 2020-2023  润新知