ASP.NET中分页AspNetPager的解释
AspNetPager组件
一、用到的组件参数
RecordCount 总记录数
StartRecordIndex 开始记录编号(用于存储过程中)
EndRecordIndex结束记录编号(用于存储过程中)
二.使用方法
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Admin_User"] == null)
{
Response.Redirect("login.aspx");
Response.End();
}
else
{
NewsSystem newsSystem = new NewsSystem();
AspNetPager1.RecordCount = newsSystem.Get_NewsNum();
}
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BinData();
}
public void BinData()
{
NewsSystem newsSystem = new NewsSystem();
News_List.DataSource = newsSystem.Get_News(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
News_List.DataBind();
}
附上存储过程:
ALTER procedure fy
(@startIndex int,
@endIndex int,
@docount int)
as
set nocount on
if(@docount=1)
select count(*) from Xt_Article
else
begin
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select id from Xt_Article order by id asc
select * from Xt_Article O,@indextable t where O.id=t.nid
and t.id between @startIndex and @endIndex order by t.id
end
set nocount off