WEB 分页功能的实现
后端C#代码部分:
// 建立Linq 数据库的连接
private MYDateDataContext context = new MYDateDataContext();

// 设定每页几条数据
private const int PAGESIZE = 3;

//获取总的页数
public int GetPageNo()
{
int PageNo =(int) Math.Ceiling(context.Car.Count()/PAGESIZE*1.0);
return PageNo;
}

//获取指定页信息的方法
public List<Car> GetPageCar( int PageNo)
{
//skip(每页固定行数*要求第几页-1).take(几行数据)
var mimi = context.Car.Skip(PAGESIZE * PageNo - 1).Take(PAGESIZE);
return mimi.ToList();
}

protected void Page_Load(object sender, EventArgs e)
{
int nowpage = 1;
if( Request["pageno"]!=null)
{
nowpage = Convert.ToInt32(Request["pageno"]);
}
List<Car> list = GetPageCar(nowpage);

// 给repeater 绑定数据源
Repeater1.DataSource = list;// 获取数据源
Repeater1.DataBind();// 绑定数据源

// 给hyup hydown 绑定数据

// 获取列表分页的最大值;
int Pageno = GetPageNo();

// 如果当前页为最大值 向上的键不可用
if (Pageno == nowpage)
{
hydown.Enabled = false;
}
else
{
hydown.Enabled = true;
hydown.NavigateUrl = "web1.aspx?pageno=" + (nowpage + 1).ToString();
}
if (nowpage == 1)
{
hyup.Enabled = false;
}
else
{

hyup.Enabled = true;
hyup.NavigateUrl = "web1.aspx?pageno=" + (nowpage - 1).ToString();
}

//给首页 绑定数据
hyfirst.NavigateUrl = "web1.aspx?pageno=1";
// 给尾页绑定数据
hyend.NavigateUrl = "web1.aspx?pageno=" + GetPageNo().ToString();

}

//跳转功能实现
protected void Button1_Click(object sender, EventArgs e)
{
int lenth = TextBox1.Text.Trim().Length;

// 将页面输入的值读取出来
if (lenth!=0 )
{
int Gono = Convert.ToInt32(TextBox1.Text);

if (Gono < 1)
{
// 如果要跳转的页面小于实际页数 跳转到本页
Response.Redirect("web1.aspx");// 跳转的指定页

}
else if (Gono > GetPageNo())
{
Response.Redirect("web1.aspx?pageno=" + GetPageNo());
}
else
{
Response.Redirect("web1.aspx?pageno=" + Gono);

}
}
else
Response.Redirect("web1.aspx");

}

前段设计部分:
注意点:HyperLink 超链接
HyperLink 控件用于创建超链接;

最新文章

  1. No.008:String to Integer (atoi)
  2. tomcat 开机后台运行
  3. Tomcat6配置webdav协议
  4. NeHe OpenGL教程 第四十七课:CG顶点脚本
  5. android 带边框的圆角按钮
  6. char* 和char[]的差别
  7. Android中九种dialog对话框代码
  8. [Xcode]使用target进行协同开发
  9. erlang-string
  10. Layx——网页弹窗最佳选择.
  11. PHP全栈学习笔记15
  12. JDK8新特性01 Lambda表达式01_设计的由来
  13. mycat 分库分表
  14. springboot mybatis 分页整合
  15. mysql 日期 字符串 时间戳转换
  16. PDO 增删改查封装的类
  17. 5.Qt模块简介
  18. leetcode刷刷刷
  19. 1、Node.js 我的开始+安装
  20. 开源自动驾驶仿真平台 AirSim (2) - 编译 AirSim

热门文章

  1. JedisPoolConfig配置
  2. MVC路由中routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;) 到底什么意思!
  3. 数据库 SQL :有关 NULL 值引发 TRUE、FALSE、UNKNOW 三值逻辑
  4. word2013中取消句首字母自动大写
  5. Car immobilizer hacking
  6. BP神经网络算法学习
  7. Codeforces Gym 100531J Joy of Flight 变换坐标系
  8. Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
  9. 【工作记录】c#操作win7注册表
  10. stm32 IAP + APP ==&gt;双剑合一