代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
程序控制分页代码
作者:
CSDN
/ 发布于
2012/1/11
/
704
<div><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)"> CurrentIndex;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">当前页数</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> Page_Load(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,0)">!</span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.IsPostBack) { DataBinds(); } } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> DataBinds() { SqlConnection cn </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> SqlConnection(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Data Source=.;Initial Catalog=Test;Integrated Security=True</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">);</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">连接并实例化数据库</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> sql </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">select * from Student</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">定义查询语句</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> SqlDataAdapter da </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> SqlDataAdapter(sql, cn);</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">实例化对象Adapter</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataSet ds </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> DataSet();</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">实例化DataSet</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> da.Fill(ds, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Student</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">);</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">填充</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> PagedDataSource pds </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> PagedDataSource();</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">初始化分页事例</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> pds.DataSource </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> ds.Tables[</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Student</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">].DefaultView; pds.AllowPaging </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">启动分页</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> pds.PageSize </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">5</span><span style="color: rgb(0,0,0)">;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">每页显示的个数</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> CurrentIndex </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">.Parse(</span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text) </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">获取当前页数索引</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> pds.CurrentPageIndex </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> CurrentIndex; </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (CurrentIndex </span><span style="color: rgb(0,0,0)">==</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">) {</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">如果是第一页,上一页和第一页的控件不可点击</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.PreviousLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.FirstLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.NextLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.EndLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (CurrentIndex </span><span style="color: rgb(0,0,0)">==</span><span style="color: rgb(0,0,0)"> pds.PageCount </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">如果是最后一页,下一页和最后一页空间不可点击</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.PreviousLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.FirstLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.NextLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.EndLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> { </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.PreviousLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.FirstLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.NextLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.EndLB.Enabled </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; } </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label2.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> pds.PageCount.ToString();</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">获取总页数</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataList1.DataSource </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> pds;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">绑定DataList数据</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataList1.DataBind(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> FirstLB_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e)</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">首页</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> { </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">1</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">页数为1</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataBinds(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> PreviousLB_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">.Parse(Label1.Text) </span><span style="color: rgb(0,0,0)">-</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">).ToString();</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">页数减1</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataBinds(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> NextLB_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e)</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">下一页</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> { </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">.Parse(</span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text) </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">).ToString();</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">页数加1</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataBinds(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> EndLB_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e)</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">末页</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> { </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Label2.Text;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">页数为最后一页</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> DataBinds(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> JumpLB_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { </span><span style="color: rgb(0,0,255)">try</span><span style="color: rgb(0,0,0)"> { </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">.Parse(TextBox1.Text) </span><span style="color: rgb(0,0,0)">></span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">&&</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">.Parse(TextBox1.Text) </span><span style="color: rgb(0,0,0)"><=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">.Parse(Label2.Text)) { </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.Label1.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> TextBox1.Text; DataBinds(); } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> { Response.Write(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)"><script>alert('请输入有效数字')</script></span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); TextBox1.Text </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">; } } </span><span style="color: rgb(0,0,255)">catch</span><span style="color: rgb(0,0,0)"> { Response.Write(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)"><script>alert('系统出错')</script></span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.Redirect(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">~/Default.aspx</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } } </span></div>
试试其它关键字
分页代码
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
CSDN
贡献的其它代码
(
27
)
.
xml操作类
.
完全无组件,不用调用Excel.exe 导出数据到Excel
.
DropDownList手动构造一个下拉树形
.
判断是否低于IE6的版本
.
javascript 鼠标拖拉画图
.
取汉字首字母
.
字符串格式化通用类
.
mssql海量高效分页存储过程
.
.net 获取远程IP 得到省市
.
javascript 模仿windows拖动 封装类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3