Search code examples
asp.netgridviewado.netobjectdatasource

Why isn't my SelectCountMethod getting called?


I'm binding a GridView to a ObjectDataSource.

I'm expecting the m_ObjectDataSourceGrid_Selected method to fire twice, once for the Select and again for the Count, but it only fires once.

What's going on?

<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>

Solution

  • You can not because you haven't assigned allowpaging, put these three:

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

    AllowPaging is needed to call the SelectCountMethod.

    remove allowsorting if not needed.