前端:
<table style="width: 100%;"> 
<tr> 
<td> 
搜索字: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
<asp:Button ID="Button1" runat="server" Text="搜索" OnClick="Button1_Click" /> 
</td> 
</tr> 
<tr> 
<td> 
<div id="divmain" runat="server"> </div> 
</td> 
</tr> 
<tr> 
<td> 
<asp:Button ID="btnFirst" runat="server" Text="首页" OnClick="btnFirst_Click" /> 
<asp:Button ID="btnPro" runat="server" Text="上一页" OnClick="btnPro_Click" /> 
<asp:Button ID="btnNext" runat="server" Text="下一页" OnClick="btnNext_Click" /> 
<asp:Button ID="btnLast" runat="server" Text="末页" OnClick="btnLast_Click" /> 
 <asp:Label ID="labCountPage" runat="server"></asp:Label> 
<asp:Label ID="labpage" runat="server"></asp:Label> 
<asp:TextBox ID="TextBox2" runat="server" Width="16px"></asp:TextBox> 
<asp:Button ID="btnGo" runat="server" OnClick="btnGo_Click" Text="Go" /> 
</td> 
</tr> 
</table>

后台:

protected void Page_Load(object sender, EventArgs e) 

if (!IsPostBack) 

ViewState["pageIndex"] = 1; 
dataPage(); 


private void dataPage() 

string constr = @"data source=.;initial catalog=News;user id=sa;password=111111;"; 
SqlConnection conn = new SqlConnection(constr); 
conn.Open(); 
SqlCommand cmd = conn.CreateCommand(); 
#region 用存储过程实现数据分页效果 
//cmd.CommandType = CommandType.StoredProcedure; 
//cmd.CommandText = "Pro_SelectNewsPage"; 
//cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"])); 
//cmd.Parameters.AddWithValue("@pageSize", 3); 
//SqlParameter parm = new SqlParameter("@count", SqlDbType.Int); 
//cmd.Parameters.Add(parm); 
//parm.Direction = ParameterDirection.Output; 
#endregion 
#region 传递SQl语句实现分页并对搜索实现分页默认显示两条记录 
cmd.CommandType = CommandType.Text; 
cmd.CommandText = "select top 2 * from (select * from T_News where NewsTitle like @title) as t where t.Id not in(select top ((@pageIndex-1)*2) t.Id from (select * from T_News where NewsTitle like @title) as t) order by t.Id"; 
cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"])); 
cmd.Parameters.AddWithValue("@title","%"+TextBox1.Text.Trim()+"%"); 
#endregion 
SqlDataAdapter adapter = new SqlDataAdapter(cmd); 
DataTable dt = new DataTable(); 
adapter.Fill(dt); 
//ViewState["pageCount"] = parm.Value; 
cmd.CommandText = "select count(*) from T_News where NewsTitle like @titles"; 
cmd.Parameters.AddWithValue("@titles", "%" + TextBox1.Text.Trim() + "%"); 
int sum = Convert.ToInt32(cmd.ExecuteScalar()); 
if (sum % 2 == 0) 

ViewState["pageCount"] = sum/2; 

else 

ViewState["pageCount"] = sum / 2 + 1; 

conn.Close(); 
conn.Dispose(); 
StringBuilder sb = new StringBuilder(); 
sb.Append("<table>"); 
foreach (DataRow row in dt.Rows) 

sb.Append("<tr><td>"+row["NewsTitle"].ToString()+"</td>"); 
sb.Append("<td>" + row["NewsContent"].ToString() + "</td>"); 
sb.Append("<td>" + row["CreateTime"].ToString() + "</td></tr>"); 

sb.Append("</table>"); 
divmain.InnerHtml = sb.ToString(); 
labCountPage.Text = "总共" + ViewState["pageCount"] + "页"; 
labpage.Text = "当前第" + ViewState["pageIndex"] + "页"; 

protected void Button1_Click(object sender, EventArgs e) 

ViewState["pageIndex"] = "1"; 
dataPage(); 

protected void btnFirst_Click(object sender, EventArgs e) 

ViewState["pageIndex"] = "1"; 
dataPage(); 

protected void btnPro_Click(object sender, EventArgs e) 

int index = Convert.ToInt32(ViewState["pageIndex"]); 
index--; 
if (index >= 1) 

ViewState["pageIndex"] = index; 
dataPage(); 


protected void btnNext_Click(object sender, EventArgs e) 

int index = Convert.ToInt32(ViewState["pageIndex"]); 
index++; 
if (index <= Convert.ToInt32(ViewState["pageCount"])) 

ViewState["pageIndex"] = index; 
dataPage(); 


protected void btnLast_Click(object sender, EventArgs e) 

ViewState["pageIndex"] =ViewState["pageCount"]; 
dataPage(); 

protected void btnGo_Click(object sender, EventArgs e) 

int i=Convert.ToInt32(TextBox2.Text); 
if (i > 0 && i <= Convert.ToInt32(ViewState["pageCount"])) 

ViewState["pageIndex"] = i; 
dataPage(); 

}

转:动态table分页(ORCALE)的更多相关文章

  1. html 布局;css3+jq 下拉菜单;table分页动态添加行;html5本地存储;简单易用的html框架

    简单好用的html框架,预览图见最后: 源码: 1.页面布局使用table: table 嵌套 +iframe 布局: 2.下拉菜单为jq+css3 动画; css input 无边框,select下 ...

  2. JQuery实现table分页

    1.直接贴代码: ; //每页显示的记录条数 ; //显示第curPage页 var len; //总行数 var page; //总页数 $(function(){ len =$(; //去掉表头 ...

  3. 项目总结17-使用layui table分页表格

    项目总结17-使用layui table分页表格总结 前言 在项目中,需要用到分页的表格来展示数据,发现layui的分页表格,是一个很好的选择:本文介绍layui table分页表格的前后端简单使用 ...

  4. Layui Table 分页记忆选中

    Layui Table 分页记忆选中 挺好的功能,之前为什么放弃了,哈哈哈! 在最早的版本中,layui 的 table 会记录每页的勾选状态,但很多用户反馈这是 bug,因为当他们获取选中数据时,其 ...

  5. Table分页显示调整

    这是table分页显示的代码,下面是对应调整的代码 /*分页调整*/ .fenye .dataTables_info{ line-height: 28px; } .fenye .pagination{ ...

  6. Bootstrap table分页问题汇总

    首先非常感谢作者针对bootstrap table分页问题进行详细的整理,并分享给了大家,希望通过这篇文章可以帮助大家解决Bootstrap table分页的各种问题,谢谢大家的阅读. 问题1 :服务 ...

  7. Table 分页处理

    介绍两种table分页处理:PHP分页 和 js(jquery.table)分页. 一:jquery.table: 1:下载两个文件:table_jui.css 和 jquery.dataTables ...

  8. bootstrap table分页(前后端两种方式实现)

    bootstrap table分页的两种方式: 前端分页:一次性从数据库查询所有的数据,在前端进行分页(数据量小的时候或者逻辑处理不复杂的话可以使用前端分页) 服务器分页:每次只查询当前页面加载所需要 ...

  9. layui table 分页 序号始终从”1“开始解决方法

    在用Layui table 分页显示数据,用 type:"numbers" 进行显示序号有以下的问题 1.表格自带的分页,page:true 这种分页,在切换页面的时候序号可以正常 ...

随机推荐

  1. android学习-Adapter适配器进阶

    参考资源 Android 快速开发系列 打造万能的ListView GridView 适配器 实现代码复用,争取打机**的时间. android4.4源码 target=android-19 一般自定 ...

  2. plt绘制 2维、3维散点图

    # 3维import numpy as np import matplotlib.pyplot as plt from sklearn.datasets.samples_generator impor ...

  3. ssh和ssh-copy-id以及批量多机无密码登陆详解

    本文主要围绕着ssh服务以及如何通过ssh-copy-id实现无密码登陆. 1. sshd 服务以及配置   2.ssh-copy-id命令的使用以及原理.3.批量多机互相信任. 1. sshd 服务 ...

  4. Spring Boot 使用Redis

    转载自:http://www.cnblogs.com/ityouknow/p/5748830.html Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化 ...

  5. redis实战笔记(6)-第6章 使用 Redis构建应用程序组件

    本章主要内容   1.构建两个前缀匹配自 动补全程序 2.通过构建分布式锁来提高性能 3.通过开发计数信号量来控制并发 4.构建两个不同用途的任务队列 5.通过消息拉取系统来实现延迟消息传递 6.学习 ...

  6. Hadoop+Hive 操作mongodb数据

    Hadoop+Hive 操作mongodb数据 1.版本概述 hadoop-2.7.3.hive-2.2 下载响应的jar包:http://mvnrepository.com/,直接搜索想要的jar包 ...

  7. RabbitMQ上手记录–part 3-发送消息

    接上一part<<RabbitMQ上手记录–part 2 - 安装RabbitMQ>>,这里我们来看看如何通过代码实现对RabbitMQ的调用. RabbitMQ通常是安装在服 ...

  8. 产环境部署node记录(三): centOS 7 mySQL和mongoDB的安装

    [mySQL的安装]: CentOS7默认数据库是mariadb,现在来安装mySQL 1.下载安装包 这里下载了四个安装包,后面会用到 yum -y install perl perl-devel ...

  9. 百度前端技术学院-task1.8源代码

    主要是不采用bootstrap实现网格. 遇到的困难及注意点如下: 1.[class*='col-'],这个是选择col-开头的类,第一次用,以前也只是看到过: 2.媒体查询,总觉得容易理解错误.@m ...

  10. Extjs相关知识点梳理

      store是一个为Ext器件提供record对象的存储容器,行为和属性都很象数据表 方法:不列举继承来的方法 Store( Object config ) 构造,config定义为{ autoLo ...