前端:
<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. 问题记录 | PyLint not recognizing cv2 members

    问题记录 | PyLint not recognizing cv2 members VScode中安装了pylint,总是提示cv2的一些成员函数找不到, 如这样的问题: Module 'cv2' h ...

  2. docker 创建elasticsearch集群镜像

    搞了2天终于搞好了 更新: 2017/2/15: 更改elasticsearch.yml中绑定ip, 可开启集群效果 //: supervisord.conf 加入 autostart=true, 开 ...

  3. Ceph 块设备 - 命令,快照,镜像

    目录 一.Ceph 块设备 二.块设备 rbd 命令 三.操作内核模块 四.快照基础 rbd snap 五.分层快照 六.镜像 rbd mirror 七.QEMU 八.libvirt 九.Openst ...

  4. SpringBoot入门 (四) 数据库访问之JdbcTemplate

    本文记录在SpringBoot中使用JdbcTemplate访问数据库. 一 JDBC回顾 最早是在上学时接触的使用JDBC访问数据库,主要有以下几个步骤: 1 加载驱动 Class.forName( ...

  5. 以中间件,路由,跨进程事件的姿势使用WebSocket--Node.js篇

    上一篇文章介绍了在浏览器端以中间件,路由,跨进程事件的姿势使用原生WebSocket.这篇文章将介绍如何使用Node.js以相同的编程模式来实现WebSocket服务端. Node.js中比较流行的两 ...

  6. jQuery二维码

    现在二维码很火,因为他可以很方便的贴到任何地方,只要扫一扫就可以看到二维码的内容 ok 废话少说,上代码 这个二维码基于jquery和jquery.qrcode插件 所以使用前先引入 <scri ...

  7. Node.js构建可扩展的Web应用1

    <Practical Node.js:Building Real-World Scalable Web Apps>[美]Azat Mardan(电子工业出版社) 安装node.js和NPM ...

  8. VB/C#获取资源Rources

    VB.Net: My.Resources.ResourceManager.GetObject("data") C# Properties.Resources.文件名

  9. 使用IDEA工具配置和运行vue项目(详细其中的坑)

    刚来公司实习发现公司的前端使用的是vue,之前根本就没有听说过.然后一上来就需要看代码,but but 就是没有文档什么的东西, 就需要自己去研读,我就想去运行其中的前端和后端联调起来方便理解,结果在 ...

  10. Tomcat配置JVM参数步骤

    这里向大家描述一下如何使用Tomcat配置JVM参数,Tomcat本身不能直接在计算机上运行,需要依赖于硬件基础之上的操作系统和一个java虚拟机.您可以选择自己的需要选择不同的操作系统和对应的JDK ...