数据库脚本:
use master
go
if exists(select name from sys.databases where name='Test_Page')
drop database Test_Page
go
create database Test_Page
go
use Test_Page
go
--表:T_Person
if exists(select name from sys.objects where name='T_Person')
drop table T_Person
go
create table T_Person
(
C_ID int identity(1,1),
C_Name nvarchar(50),
C_Address nvarchar(200),
C_Call varchar(11),
constraint PK_T_Person_C_ID primary key(C_ID)
)
go
--insert into T_Person(C_Name,C_Address,C_Call) values('curitsyang','广东深圳','12510441277')
--go
--存储过程;InsertIntoT_Person
if exists(select name from sys.objects where name='InsertIntoT_Person')
drop procedure InsertIntoT_Person
go
create procedure InsertIntoT_Person
as
begin
declare @i int
set @i=0
while(@i<10)
begin
insert into T_Person(C_Name,C_Address,C_Call) values('curitsyang','广东深圳','13510441277')
set @i=@i+1
end
end
go
execute InsertIntoT_Person
go
select * from T_Person
go
aspx:
<asp:Repeater ID="Repeater_1" runat="server">
<HeaderTemplate>
<div>
</div>
<table cellpadding="0" cellspacing="0" id="main">
<caption style=" 450px; height: 40px; line-height: 45px; text-align: center;">
<strong>Person</strong></caption>
<tr>
<td>
编号
</td>
<td>
姓名
</td>
<td>
地址
</td>
<td>
电话
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("C_ID") %>
</td>
<td>
<%# Eval("C_Name") %>
</td>
<td>
<%# Eval("C_Address") %>
</td>
<td>
<%# Eval("C_Call") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div style="margin-top: 5px;">
</div>
<webdiyer:AspNetPager ID="AnpFy" runat="server" AlwaysShow="true" FirstPageText="第一页"
PrevPageTex="上一页" NextPageText="下一页" LastPageText="最后一页" PageSize="3" OnPageChanged="AspNetPage_Changed">
</webdiyer:AspNetPager>
aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
this.Bind();
}
}
protected void Bind()
{
string sql = "select * from T_Person";
Repeater_1.DataSource = PageFenYe(new SQLHelper().ExecuteDataTable(sql));
Repeater_1.DataBind();
}
private PagedDataSource PageFenYe(System.Data.DataTable table)
{
this.AnpFy.RecordCount = table.Rows.Count;
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = table.DefaultView;
pds.CurrentPageIndex = this.AnpFy.CurrentPageIndex - 1;
pds.PageSize = this.AnpFy.PageSize;
return pds;
}
protected void AspNetPage_Changed(object sender, EventArgs e)
{
this.Bind();
}