2010-06-23 63 views
0

我有一個Gridview顯示來自搜索查詢的分頁結果。我遇到的問題是gridview沒有顯示查詢返回的所有結果。例如,我可以遍歷代碼並查看調用GetList()返回的6個項目,但綁定後只有2行由gridview呈現。ASP.NET Gridview不綁定到自定義列表中的所有項目

我正在使用的代碼創建一個ObjectDataSource:

ObjectDataSource ods = new ObjectDataSource(); 

ods.EnablePaging = true; 
ods.TypeName = "Bll.InvestmentProductSvc"; 
ods.DataObjectTypeName = "Bll.InvestmentProduct"; 
ods.SelectMethod = "GetList"; 

ods.SelectCountMethod = "GetListCount"; 
ods.StartRowIndexParameterName = "PageIndex"; 
ods.MaximumRowsParameterName = "PageSize"; 
ods.EnableViewState = false; 

ods.SelectParameters.Add (new Parameter("SearchString",TypeCode.String, SearchString)); 
ods.SelectParameters.Add(new Parameter("PageIndex", TypeCode.Int32)); 
ods.SelectParameters.Add(new Parameter("PageSize", TypeCode.Int32, gvSearchResults.PageSize.ToString())); 

gvSearchResults.DataSource = ods; 
gvSearchResults.DataBind(); 

在GridView聲明:

<asp:GridView ID="gvSearchResults" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageIndex="0" PageSize="50" OnPageIndexChanging="gvSearchResults_PageIndexChanging" PagerSettings-Position="TopAndBottom"> 
</asp:GridView> 

是否有GridView控件不使行和報告的任何原因錯誤? 我檢查了6個項目返回的數據,在顯示的2行和未顯示的4行之間找不到任何顯着差異。由歸國

回答

1

檢查的行數:

ods.SelectCountMethod = "GetListCount"; 
+0

謝謝,你釘它!一段時間後,GetListCount()還沒有更新,導致結果不一致。 – HectorMac 2010-06-23 14:13:15