4

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>
Homer
  • 7,594
  • 14
  • 69
  • 109
  • Please provide more details. What is `Count`? – Amit May 13 '11 at 21:07
  • Count is the count, meaning, the value I expect to get from `e.ReturnValue` when m_ObjectDataSourceGrid_Selected fires the second time. – Homer May 13 '11 at 21:13
  • Weird, didn't you just answer here,http://stackoverflow.com/questions/2915555/how-do-i-tell-if-the-objectdatasource-onselected-event-was-called-for-the-selectm/5997878#5997878 , that it was getting fired twice? – itchi May 14 '11 at 05:32
  • 2
    Does the gridview have the AllowPaging set to true? Can you show some code? – onof May 14 '11 at 12:13
  • @itchi, I did answer there. That is the code I'm using in other apps, but it's not working here and I don't know why. I know I could just get the count myself in the DataBound method, but I'd like to know why this isn't working. – Homer May 16 '11 at 13:50

2 Answers2

3

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.

Ali Adravi
  • 21,707
  • 9
  • 87
  • 85
2

Does your SelectCountMethod is receiving the same parameters as SelectMethod? There's two ways that makes SelectCountMethod acceptable: without any parameter "()" or with the same parameters as SelectMethod, besides Sorting and Paging parameters.

thiagoprzy
  • 411
  • 2
  • 8
  • 21