2011-08-22 57 views
6

我正在使用PagedDataSource進行gridview的自定義分頁。下面是代碼: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(); 

我返回從我的存儲過程中的「totalrows」(這是在virtualRowCount設置)和實際行數據集中的tables[0]。我得到的結果,但我的傳呼機已經消失。尋呼機不再顯示。我如何告訴gridview從PagedDataSource中獲取值?

與ASP.Net 4

+0

請你能接受這個答案,因爲我不認爲你會看到多少movementon它。 – bUKaneer

回答

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屬性?

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

+0

這隻適用於ASP 4.5 mate – Jupaol

+0

抱歉錯過了關於框架版本的評論!我認爲AllowPaging存在? – bUKaneer

+0

Yeap,這是由於某種原因VirtualCount屬性被忽略 – Jupaol

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