会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
yangtu86
博客园
::
首页
::
博问
::
闪存
::
新随笔
::
联系
::
订阅
::
管理
::
公告
AspNetPager+DataGrid
<
P
><
WEBDIYER:ASPNETPAGER
id
="pager"
runat
="server"
SubmitButtonText
="转到"
ShowPageIndex
="False"
PageSize
=2
ShowInputBox
="Always"
LastPageText
="<font style='FONT-SIZE: x-small'>最后页</fornt>"
NextPageText
="<font style='FONT-SIZE: x-small'>下一页</fornt>"
PrevPageText
="<font style='FONT-SIZE: x-small'>前一页</fornt>"
FirstPageText
="<font style='FONT-SIZE: x-small'>最前页</fornt>"
InputBoxStyle
="border:1px #0000FF solid;text-align:center;FONT-SIZE: x-small"
TextBeforeInputBox
="第"
TextAfterInputBox
="页"
ShowCustomInfoSection
="left"
AlwaysShow
="True"
CustomInfoTextAlign
="Center"
SubmitButtonStyle
="width:40px;height:21px;"
></
webdiyer:AspNetPager
></
P
>
<
P
><
asp:datagrid
id
="dgrid1"
runat
="server"
></
asp:datagrid
></
P
>
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
namespace
InfoId.cc
{
/**/
///
<summary>
///
test 的摘要说明。
///
</summary>
public
class
test : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.DataGrid dgrid1;
protected
Wuqi.Webdiyer.AspNetPager pager;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
if
(
!
Page.IsPostBack)
{
BindData();
}
}
private
void
BindData()
{
SqlConnection conn
=
new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[
"
SqlConnectionString
"
].ToString());
SqlCommand cmd
=
new
SqlCommand(
"
select * from test
"
,conn);
SqlDataAdapter da
=
new
SqlDataAdapter(cmd);
DataSet ds
=
new
DataSet();
//
注意下面这句,只填充当前页要显示的数据,不能把所有数据全填充到DataSet中,否则无法实现分页
da.Fill(ds,pager.PageSize
*
(pager.CurrentPageIndex
-
1
),pager.PageSize,
"
newtable
"
);
dgrid1.DataSource
=
ds.Tables[
"
newtable
"
];
dgrid1.DataBind();
DataSet ds1
=
new
DataSet();
da.Fill(ds1);
pager.RecordCount
=
ds1.Tables[
0
].Rows.Count;
//
动态设置用户自定义文本内容
pager.CustomInfoText
=
"
记录总数:<font color='blue'><b>
"
+
pager.RecordCount.ToString()
+
"
</b></font>
"
;
pager.CustomInfoText
+=
"
总页数:<font color='blue'><b>
"
+
pager.PageCount.ToString()
+
"
</b></font>
"
;
pager.CustomInfoText
+=
"
当前页:<font color='red'><b>
"
+
pager.CurrentPageIndex.ToString()
+
"
</b></font>
"
;
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.pager.PageChanged
+=
new
Wuqi.Webdiyer.PageChangedEventHandler(
this
.pager_PageChanged);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
pager_PageChanged(
object
src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
pager.CurrentPageIndex
=
e.NewPageIndex;
BindData();
System.Text.StringBuilder sb
=
new
System.Text.StringBuilder(
"
<script Language=\
"
Javascript\
"
><!--\n
"
);
sb.Append(
"
var el=document.all;
"
);
sb.Append(dgrid1.ClientID);
sb.Append(
"
.scrollIntoView(true);
"
);
sb.Append(
"
<
"
);
sb.Append(
"
/
"
);
sb.Append(
"
script>
"
);
if
(
!
Page.IsStartupScriptRegistered(
"
scrollScript
"
))
Page.RegisterStartupScript(
"
scrollScript
"
,sb.ToString());
}
}
}
posted on
2006-06-27 14:11
杨土
阅读(
347
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部