代码之家  ›  专栏  ›  技术社区  ›  HectorMac

ASP.NET GridView未绑定到自定义列表中的所有项

  •  0
  • HectorMac  · 技术社区  · 15 年前

    我有一个网格视图,显示搜索查询的分页结果。我遇到的问题是,GridView没有显示从查询返回的所有结果。例如,我可以单步执行代码,并看到调用getList()返回的6个项目,但是绑定之后,只有2行由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>
    

    网格视图不呈现行有什么原因吗? 报告错误? 我已经检查了返回的6个项目的数据,没有发现显示的2行和未显示的4行之间有任何区别。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Dewfy    15 年前

    检查返回的行数:

    ods.SelectCountMethod = "GetListCount";