zoukankan      html  css  js  c++  java
  • 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;

    }

    }

  • 相关阅读:
    机器学习中的数学(1)-回归(regression)、梯度下降(gradient descent)
    机器学习中的数学(4)-线性判别分析(LDA), 主成分分析(PCA)
    机器学习中的数学(5)-强大的矩阵奇异值分解(SVD)及其应用
    Shell遍历文件的每一行[转载]
    从C中变化过来的各种语言的printf输出格式
    PostgreSQL中的引号和null
    linux入门基础_centos(二)--fdisk分区
    linux入门基础_centos(一)--基础命令和概念
    centos中设置apache显示目录列表
    转载:centos上yum安装apache+php+mysql等
  • 原文地址:https://www.cnblogs.com/cf924823/p/5069005.html
Copyright © 2011-2022 走看看