您的位置:首页 > 编程语言 > ASP

AspnetPager分页控件的使用

2007-09-28 15:46 393 查看
用了几次吴旗娃的分页控件,觉得蛮好用的,但每次用都因为没有保存代码,所以后来再想用的时候就没有了.郁闷之极.

看吴旗娃的例子对于我这个新手来说还有一定的难度,希望以后能看懂吧, 现在就把自己通过Google 、Baidu搜索出的解决方法和吴旗娃的文档结合起来所得到分页代码收藏起来,以备后用! 都是通过测试,已经成功了的!

一、


<webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged"


pagesize="3"></webdiyer:aspnetpager>


void BindData()




...{


PagedDataSource pds = new PagedDataSource();


pds.AllowPaging = true;


pds.PageSize = AspNetPager1.PageSize;


pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;


DataView dv = (DataView)GBDS.Select(DataSourceSelectArguments.Empty);


pds.DataSource = dv;


GB.DataSource = pds;


GB.DataBind();


}


protected void AspNetPager1_PageChanged(object sender, EventArgs e)




...{


BindData();


}


protected void GBDS_Selected(object sender, SqlDataSourceStatusEventArgs e)




...{


AspNetPager1.RecordCount = e.AffectedRows;


}

其中的GB为GridView控件,GBDS为SqlDatasource控件,这个示例是在sqldatasource控件通过向导与数据库进行连接的。

二、


//绑定分页控件


AspNetPager1.RecordCount = source.Count;


PagedDataSource pds = new PagedDataSource();


pds.DataSource = source;


pds.AllowPaging = true;


pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;


pds.PageSize = AspNetPager1.PageSize; ;


dgMailList.DataSource = pds;


dgMailList.DataBind();


<webdiyer:aspnetpager id="AspNetPager1" runat="server"


OnPageChanged="AspNetPager1_PageChanged" PageSize="1"></webdiyer:aspnetpager></center>



这个示例是采用的存储过程检索数据然后返回DataTable。再将表转换成视图。。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: