用于gridview分页的PagedDatasource

时间:2011-08-22 08:14:56

标签: asp.net gridview paging custompaging

我正在使用PagedDataSource进行gridview的自定义分页。这是代码:

PagedDataSource dataSource = new PagedDataSource();

int virtualRowCount = Convert.ToInt32(dataset.Tables[1].Rows[0]["TotalRows"]);
dataSource.AllowCustomPaging = true;
dataSource.PageSize = 15;

dataSource.VirtualCount = virtualRowCount;
dataSource.DataSource = dataset.Tables[0].DefaultView;


gvTaxPayerLoginDetail.DataSource = dataSource;
gvTaxPayerLoginDetail.DataBind();

我从我的存储过程(在virtualRowCount中设置)和数据集tables[0]中的实际行返回“totalrows”。我得到的结果,但我的寻呼机消失了。寻呼机不再显示。如何告诉gridview从PagedDataSource中获取值?

使用ASP.Net 4

2 个答案:

答案 0 :(得分:3)

ASP.NET 2.0+版本

这篇文章http://www.codewrecks.com/blog/index.php/2008/02/09/aspnet-20-gridview-custom-sorting-with-pageddatasource/扩展了标准的GridView,并提供了管道代码来实现PagedDataSource集成。

ASP.NET 4.5版本

在GridView上设置AllowPaging和AllowCustomPaging属性以及Paged数据源属性?

PagedDataSource dataSource = new PagedDataSource();

int virtualRowCount = Convert.ToInt32(dataset.Tables[1].Rows[0]["TotalRows"]);
dataSource.AllowCustomPaging = true;
dataSource.PageSize = 15;

dataSource.VirtualCount = virtualRowCount;
dataSource.DataSource = dataset.Tables[0].DefaultView;

gvTaxPayerLoginDetail.AllowPaging = true; // See this line here
gvTaxPayerLoginDetail.AllowCustomPaging = true; // and this line here
gvTaxPayerLoginDetail.DataSource = dataSource;
gvTaxPayerLoginDetail.DataBind();

此外,这篇文章也可能有所帮助http://www.byteblocks.com/post/2012/03/20/Use-Custom-Paging-in-Grid-View.aspx

答案 1 :(得分:1)

PagedDataSource dataSource = new PagedDataSource();

int virtualRowCount = Convert.ToInt32(dataset.Tables[1].Rows[0]["TotalRows"]);

dataSource.DataSource = dataset.Tables[0].DefaultView;

dataSource.AllowCustomPaging = true;
dataSource.PageSize = 15;
dataSource.VirtualCount = virtualRowCount;
dataSource.CurrentPageIndex  =0;

gvTaxPayerLoginDetail.DataSource = dataSource;
gvTaxPayerLoginDetail.AllowPaging=True;
gvTaxPayerLoginDetail.DataBind();