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

最佳答案

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

关于asp.net - 为什么我的SelectCountMethod不被调用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5997752/

10-10 15:54