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;

    }

    }

  • 相关阅读:
    python定义函数时的默认返回值
    【UNIX网络编程】配置unp.h和apueerror.h
    【UNIX网络编程】套接字编程简介
    【UNIX网络编程】概述
    【VSCode】Ubuntu下VSC编译运行c++程序
    【UNIX网络编程】传输层:TCP、UDP和SCTP
    nginx跨域配置
    centOS7.*安装nginx和简单使用
    nginx日志切割
    nginx静态资源防盗链
  • 原文地址:https://www.cnblogs.com/cf924823/p/5069005.html
Copyright © 2011-2022 走看看