【问题标题】:Why isn't my SelectCountMethod getting called?为什么我的 SelectCountMethod 没有被调用?
【发布时间】:2011-05-13 21:04:36
【问题描述】:

我将GridView 绑定到ObjectDataSource

我预计 m_ObjectDataSourceGrid_Selected 方法会触发两次,一次用于 Select,一次用于 Count,但它只触发一次。

发生了什么事?

<asp:GridView ID="m_GridViewDocClasses" runat="server" AutoGenerateColumns="False"
            DataSourceID="m_ObjectDataSourceGrid" 
            AllowSorting="true">
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="DocClass.aspx?DocClassId={0}"
                    Text="Edit" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />                    
            </Columns>
        </asp:GridView>
    </div>
    <asp:ObjectDataSource ID="m_ObjectDataSourceGrid" runat="server" SelectMethod="GetDocClasses"
        TypeName="SouthernCompany.Generation.SPORT.Business.DocClassBL" OnObjectCreating="m_ObjectDataSourceGrid_ObjectCreating"
        OnSelected="m_ObjectDataSourceGrid_Selected" SelectCountMethod="GetDocClassesCount"
        SortParameterName="sort">
        <SelectParameters>
            <asp:Parameter DefaultValue="" Name="sort" Type="String" />
            <asp:Parameter DefaultValue="0" Name="startRowIndex" Type="Int32" />
            <asp:Parameter DefaultValue="0" Name="maximumRows" Type="Int32" />
            <asp:Parameter DefaultValue="0" Name="docClassId" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

【问题讨论】:

  • 请提供更多细节。什么是Count
  • Count 是计数,意思是当 m_ObjectDataSourceGrid_Selected 第二次触发时我希望从e.ReturnValue 获得的值。
  • 奇怪,你刚才不是在这里回答stackoverflow.com/questions/2915555/…,它被解雇了两次吗?
  • gridview 是否将 AllowPaging 设置为 true?你能显示一些代码吗?
  • @itchi,我确实在那里回答了。那是我在其他应用程序中使用的代码,但它在这里不起作用,我不知道为什么。我知道我可以自己在 DataBound 方法中获得计数,但我想知道为什么这不起作用。

标签: asp.net gridview ado.net objectdatasource


【解决方案1】:

你不能因为你没有分配allowpaging,就把这三个:

AllowPaging="true" 
AllowSorting="true"
PageSize="25"

调用 SelectCountMethod 需要 AllowPaging。

如果不需要,请删除允许排序。

【讨论】:

  • 另外,ObjectDataSource 上的EnablePaging="true"
【解决方案2】:

您的 SelectCountMethod 是否接收与 SelectMethod 相同的参数?有两种方法可以使 SelectCountMethod 可接受:除了 Sorting 和 Paging 参数外,没有任何参数“()”或与 SelectMethod 具有相同的参数。

【讨论】:

  • SelectMethod 和 SelectCountMethod 都接收相同的 4 个参数。
猜你喜欢
  • 2018-07-11
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 2022-10-15
  • 2011-04-11
  • 2023-03-07
  • 1970-01-01
相关资源
最近更新 更多