zoukankan
html css js c++ java
VS2005中使用AspNetPager控件成功事例代码(分页超快的哟)
效果图片:
显示页面的Html代码:
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
AspNetPager.aspx.cs
"
Inherits
=
"
AspNetPager
"
%>
<%
@ Register Assembly
=
"
AspNetPager
"
Namespace
=
"
Wuqi.Webdiyer
"
TagPrefix
=
"
webdiyer
"
%>
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head runat
=
"
server
"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div style
=
"
text-align: center
"
>
<
asp:TextBox ID
=
"
TextBox1
"
runat
=
"
server
"
></
asp:TextBox
>
<
asp:Button ID
=
"
Button1
"
runat
=
"
server
"
Text
=
"
Button
"
/><
br
/>
<
div style
=
"
100px; height: 448px
"
>
<
asp:GridView ID
=
"
GridView1
"
runat
=
"
server
"
Width
=
"
664px
"
Height
=
"
64px
"
OnRowDataBound
=
"
GridView1_RowDataBound
"
>
</
asp:GridView
>
</
div
>
<
br
/>
<
asp:Label ID
=
"
CustomInfoClass
"
runat
=
"
server
"
></
asp:Label
><
br
/>
<
webdiyer:AspNetPager ID
=
"
AspNetPager1
"
runat
=
"
server
"
UrlPaging
=
"
true
"
PageSize
=
"
10
"
ShowCustomInfoSection
=
"
Left
"
NumericButtonTextFormatString
=
"
[{0}]
"
AlwaysShow
=
"
true
"
OnPageChanged
=
"
AspNetPager1_PageChanged
"
Width
=
"
296px
"
CustomInfoSectionWidth
=
"
60%
"
ShowInputBox
=
"
Never
"
TextAfterInputBox
=
""
TextBeforeInputBox
=
""
>
</
webdiyer:AspNetPager
>
</
div
>
</
form
>
</
body
>
</
html
>
显示页面的CS代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
using
System.Text;
public
partial
class
AspNetPager : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
this
.IsPostBack)
{
getLog();
}
}
private
void
getLog()
{
string
con
=
ConfigurationManager.ConnectionStrings[
"
AspNetPagerConnectionString
"
].ConnectionString;
SqlConnection dbconnection
=
new
SqlConnection(con);
try
{
SqlCommand cmd
=
new
SqlCommand(
"
select count(newsid) from wqnews
"
, dbconnection);
SqlDataAdapter sda
=
new
SqlDataAdapter(cmd);
//
wqnews可以是别名
DataSet ds
=
new
DataSet(
"
wqnews
"
);
sda.Fill(ds,
"
wqnews
"
);
this
.AspNetPager1.RecordCount
=
Convert.ToInt32(ds.Tables[
0
].Rows[
0
][
0
]);
Response.Write(ds.Tables[
0
].Rows[
0
][
0
]);
}
catch
(Exception e)
{
Response.Write(e.Message);
}
BindData();
}
private
void
BindData()
{
string
con
=
ConfigurationManager.ConnectionStrings[
"
AspNetPagerConnectionString
"
].ConnectionString;
SqlConnection dbconnection
=
new
SqlConnection(con);
int
RecordPage
=
(AspNetPager1.CurrentPageIndex
-
1
)
*
AspNetPager1.PageSize;
//
string strsql =string.Format("select * from wqnews order by addtime desc",AspNetPager1.PageSize.ToString(),RecordPage.ToString());
SqlCommand cmd
=
new
SqlCommand(
"
select * from wqnews order by addtime desc
"
,dbconnection);
DataSet ds
=
new
DataSet();
SqlDataAdapter sda
=
new
SqlDataAdapter(cmd);
sda.Fill(ds, RecordPage,AspNetPager1.PageSize,
"
wqnews
"
);
this
.GridView1.DataSource
=
ds.Tables[
0
];
this
.GridView1.DataBind();
//
动态设置用户自定义文本内容
sda.Dispose();
AspNetPager1.CustomInfoClass
=
"
记录总数:<font color=\
"
blue\
"
><b>
"
+
AspNetPager1.RecordCount.ToString()
+
"
</b></font>
"
;
AspNetPager1.CustomInfoClass
+=
"
总页数:<font color=\
"
blue\
"
><b>
"
+
AspNetPager1.PageCount.ToString()
+
"
</b></font>
"
;
AspNetPager1.CustomInfoClass
+=
"
当前页:<font color=\
"
red\
"
><b>
"
+
AspNetPager1.CurrentPageIndex.ToString()
+
"
</b></font>
"
;
CustomInfoClass.Text
=
AspNetPager1.CustomInfoClass;
}
protected
void
AspNetPager1_PageChanged(
object
src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
this
.AspNetPager1.CurrentPageIndex
=
e.NewPageIndex;
BindData();
StringBuilder sb
=
new
StringBuilder(
"
<script Language=\
"
Javascript\
"
><!--\n
"
);
sb.Append(
"
var el=document.all;
"
);
sb.Append(
this
.GridView1.ClientID);
sb.Append(
"
.scrollIntoView(true);
"
);
sb.Append(
"
<
"
);
sb.Append(
"
/
"
);
sb.Append(
"
script>
"
);
if
(
!
ClientScript.IsStartupScriptRegistered(
"
scrollScript
"
))
{
ClientScript.IsStartupScriptRegistered(sb.ToString());
}
}
protected
void
GridView1_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType
==
DataControlRowType.DataRow)
{
e.Row.Attributes.Add(
"
onMouseOver
"
,
"
c=this.style.backgroundColor;this.style.backgroundColor='eafae9';
"
);
e.Row.Attributes.Add(
"
onMouseOut
"
,
"
this.style.backgroundColor=c;
"
);
}
}
}
查看全文
相关阅读:
重定向输出流实现程序日志
为新员工分配部门
从控制台接收输入的身份证号
判断某一年是否为闰年
linux重置mysql密码(root权限)
mysql按照字符串类型的数值按数值进行排序
android 下拉刷新
android studio gradle 配置
搭建自己的iOS内测分发平台
http_range说明
原文地址:https://www.cnblogs.com/chenbg2001/p/1709469.html
最新文章
非法吸收公众存款罪的6大无罪辩点(根据无罪判例提炼)
[nRF51822] 15、穿戴式设备上电量检测装置的设计及细节技术点(偏专业硬件文章)
[小黑科技] 分享一个可以节省你30分钟的博客园个人博客目录自动生成引擎(过来试玩)
[nRF51822] 14、浅谈蓝牙低功耗(BLE)的几种常见的应用场景及架构(科普类干货)
[nRF51822] 13、浅谈nRF51822和NRF24LE1/NRF24LU1/NRF24L01经典2.4G模块无线通信配置与流程
[nRF51822] 12、基础实验代码解析大全 · 实验19
[nRF51822] 11、基础实验代码解析大全 · 实验16
[nRF51822] 10、基础实验代码解析大全 · 实验15
[nRF51822] 9、基础实验代码解析大全 · 实验12
[nRF51822] 8、基础实验代码解析大全 · 实验11
热门文章
[nRF51822] 7、基础实验代码解析大全(前十)
[前端] 1、分享一个基于博客园的标签云制作方法
[ZigBee] 16、Zigbee协议栈应用(二)——基于OSAL的无线控制LED闪烁分析(下)
[ZigBee] 15、Zigbee协议栈应用(一)——Zigbee协议栈介绍及简单例子(长文,OSAL及Zigbee入门知识)
[ZigBee] 14、Zigbee无线通信前奏——BasicRF 简单无线点对点传输协议
[商业_法务] 1、公司一款新消费类电子产品如何快速全面的专利保护
验证IP地址的有效性
人民币金额转换为大写
使用List集合传递传递学生信息
动态数组保存学生姓名
Copyright © 2011-2022 走看看