【问题标题】:ASP.NET Gridview not binding to all items in Custom ListASP.NET Gridview 未绑定到自定义列表中的所有项目
【发布时间】:2010-06-23 12:44:46
【问题描述】:

我有一个显示来自搜索查询的分页结果的 Gridview。我遇到的问题是gridview 没有显示查询返回的所有结果。例如,我可以单步执行代码并查看调用 GetList() 返回的 6 个项目,但绑定后 gridview 只呈现 2 行。

我正在使用在代码中创建的 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 行之间找不到任何明显的差异。

【问题讨论】:

    标签: asp.net gridview


    【解决方案1】:

    检查返回的行数:

    ods.SelectCountMethod = "GetListCount";
    

    【讨论】:

    • 谢谢,你成功了! GetListCount() 在一些更改后没有更新,导致结果不一致。
    猜你喜欢
    • 1970-01-01
    • 2011-09-09
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    相关资源
    最近更新 更多