前端:
<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. Linux-(touch,cat,nl,more|less,head|tail)

    touch命令 1.命令格式: touch [选项]... 文件... 2.命令参数: -a   或--time=atime或--time=access或--time=use  只更改存取时间. -c ...

  2. 笔记四:python乱码深度剖析二

    一:学习内容 获取更改系统编码 判断字符的编码类型 文件存储和读取的编码 二:获取更改系统编码 1. 获取系统编码 import sys print sys.getdefaultencoding() ...

  3. 用java做操作系统内核:软盘读写

    在前两节,我们将一段代码通过软盘加载到了系统内存中,并指示cpu执行加入到内存的代码,事实上,操作系统内核加载也是这么做的.只不过我们加载的代码,最大只能512 byte, 一个操作系统内核,少说也要 ...

  4. 用java实现一个简易编译器-语法解析

    语法和解析树: 举个例子看看,语法解析的过程.句子:“我看到刘德华唱歌”.在计算机里,怎么用程序解析它呢.从语法上看,句子的组成是由主语,动词,和谓语从句组成,主语是“我”,动词是“看见”, 谓语从句 ...

  5. 学习angualr之前需要了解的typeScript知识

    官网 : www.typescriptlang.org   1.编译型语言 2.强类型语言 3.真正的面向对象的语言: 有借口.有泛型.有枚举.有访问修饰符 AMD类型的面向对象的语言     npm ...

  6. vue-cli中引入jquery

    vue-cli 在引入bootstrap时总是报找不到jquery.(模板用的webpack) 在webpack.base.conf.js里加入 var webpack = require(" ...

  7. 通向全栈之路——(4)nginx反向代理配置

    1.安装nginx:sudo apt-get install nginx2.新建配置文件:cd /etc/nginx/conf.dsudo vi XXX-cn-8080.conf内容如下:upstre ...

  8. Jsp&Servlet入门级项目全程实录第4讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.添加搜索.添加.修改.删除按钮 <div id="tb"> <div> ...

  9. 转载:sql用逗号连接多张表对应哪个join?

    http://blog.csdn.net/huanghanqian/article/details/52847835 四种join的区别已老生常谈: INNER JOIN(也可简写为JOIN): 如果 ...

  10. Spring系列之——使用了哪些设计模式

    1 工厂模式:BeanFactory.ApplicationContext创建中 2 模板模式:BeanFactory.ApplicationContext实现中 3 代理模式:在AOP实现中用到了J ...