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;

}

}

 

转载于:https://www.cnblogs.com/cf924823/p/5069005.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值