using
System;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
using
;
///
<summary>
///
说明:本文介绍如何利用AjaxPro技术实现翻页时局部刷新,同时也介绍了翻页所涉及到的数据库知识(MySQL、MS SQL和Oracle)。
///
本演示程序采用MySQL数据库,数据库中的数据是采用程序随机生成的。
///
首发地址:/zhoufoxcn/archive/2008/03/12/
///
作者:周公
///
日期:2008-3-12
///
</summary>
public
partial
class
AjaxPager :
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
(
typeof
(AjaxPager));
}
///
<summary>
///
从数据库中指定位置读取指定数目的数据
///
</summary>
///
<param name="startIndex">
记录的起始页位置
</param>
///
<param name="size">
要读取的记录条数
</param>
///
<returns></returns>
[]
public
DataTable GetDataTable(
int
pageIndex,
int
size)
{
MySqlConnection connection
=
new
MySqlConnection([
"
MySql
"
].ConnectionString);
MySqlDataAdapter adapter
=
new
MySqlDataAdapter(
"
select * from userlist limit
"
+
(pageIndex
-
1
)
*
size
+
"
,
"
+
size, connection);
DataTable data
=
new
DataTable();
(data);
();
();
return
data;
}
///
<summary>
///
传递div节点的html字符串
///
</summary>
///
<param name="startIndex">
记录的起始页位置
</param>
///
<param name="size">
要读取的记录条数
</param>
///
<returns></returns>
[]
public
string
GetString(
int
pageIndex,
int
size)
{
StringBuilder text
=
new
StringBuilder();
(
"
<table border='0' cellpadding='0' cellspacing='0' width='520px'>
"
);
(
"
<tr class='items' align='center'>
"
);
(
"
<td style='width:80px'>编号</td>
"
);
(
"
<td style='width:80px'>姓名</td>
"
);
(
"
<td style='width:80px'>年龄</td>
"
);
(
"
<td style='width:80px'>性别</td>
"
);
(
"
<td style='width:80px'>身高</td>
"
);
(
"
<td style='width:80px'>工资</td>
"
);
(
"
</tr>
"
);
DataTable source
=
GetDataTable(pageIndex,size);
DataRow row;
for
(
int
i
=
0
; i
<
; i
++
)
{
row
=
[i];
(
"
<tr class='table' align='center'>
"
);
for
(
int
column
=
0
; column
<
; column
++
)
{
(
"
<td style='width:80px'>
"
+
row[column].ToString()
+
"
</td>
"
);
}
(
"
</tr>
"
);
}
int
pageCount
=
(
int
)((GetRecordCount()
/
(
double
)size));
(
"
<tr class='items' align='center'>
"
);
(
"
<td><a href='javascript:JumpPage(1)'>首页</a></td>
"
);
if
(pageIndex
<
pageCount)
{
(
"
<td><a href='javascript:JumpPage(
"
+
(pageIndex
+
1
)
+
"
)'>下一页</a></td>
"
);
}
else
{
(
"
<td>下一页</a></td>
"
);
}
if
(pageIndex
>
1
)
{
(
"
<td><a href='javascript:JumpPage(
"
+
(pageIndex
-
1
)
+
"
)'>上一页</a></td>
"
);
}
else
{
(
"
<td>上一页</a></td>
"
);
}
(
"
<td><a href='javascript:JumpPage(
"
+
pageCount
+
"
)'>尾页</a><td>
"
);
(
"
<td>当前页:
"
+
pageIndex
+
"
/
"
+
pageCount
+
"
</td>
"
);
(
"
</table>
"
);
return
();
}
///
<summary>
///
返回记录总条数
///
</summary>
///
<returns></returns>
[]
public
int
GetRecordCount()
{
MySqlConnection connection
=
new
MySqlConnection([
"
MySql
"
].ConnectionString);
MySqlCommand command
=
new
MySqlCommand(
"
select count(userId) from userlist
"
, connection);
();
int
count
=
int
.Parse(().ToString());
();
();
return
count;
}
}