码迷,mamicode.com
首页 > 其他好文 > 详细

12.23,repeater 分页显示

时间:2015-12-23 10:51:06      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

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;

}

技术分享

}

 

12.23,repeater 分页显示

标签:

原文地址:http://www.cnblogs.com/cf924823/p/5069005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!