6

我正在使用 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

4

2 回答 2

3

ASP.NET 2.0+ Version

This post here http://www.codewrecks.com/blog/index.php/2008/02/09/aspnet-20-gridview-custom-sorting-with-pageddatasource/ extends the standard GridView and provides plumbing code to achieve PagedDataSource integration.

ASP.NET 4.5 Version

Set the AllowPaging and AllowCustomPaging attribute on the GridView as well as the Paged data source property?

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();

Additionally this post may also be of help http://www.byteblocks.com/post/2012/03/20/Use-Custom-Paging-in-Grid-View.aspx

于 2012-08-13T13:15:04.010 回答
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();
于 2012-08-18T20:27:40.567 回答