Search code examples
c#asp.netpaginationobjectdatasourcecustompaging

ObjectDataSource paging and extra parameters


I'm using an ObjectDataSource to sort/page/filter as below:

        <asp:ObjectDataSource 
                ID="odsCompaniesIndex" runat="server" EnablePaging="true"  
                   SelectMethod="GetCompaniesSubset" 
                   StartRowIndexParameterName="startRowIndex" 
                   MaximumRowsParameterName="maximumRows"
                   SelectCountMethod="GetCompaniesCount" 
                   SortParameterName="sortExpression" 
                   TypeName="Company">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlStatus" 
                 ConvertEmptyStringToNull="true" 
                 DbType="Boolean" PropertyName="SelectedValue" Name="status" />
        </SelectParameters>
    </asp:ObjectDataSource>

The gridview consuming the ObjectDataSource:

        <asp:GridView ID="gvCompanyIndex" AutoGenerateColumns="true" runat="server" DataSourceID="odsCompaniesIndex"
        AllowPaging="true" DataKeyNames="company_id" AllowSorting="true">
    </asp:GridView>

I want to pass in a number of parameters like the one above into SelectParameters. The method call 'GetCompaniesSubset' executes but on the return I get the following error:

ObjectDataSource 'odsCompaniesIndex' could not find a non-generic method 'GetCompaniesCount' that has parameters: status.

My SelectMethod is:

    public DataSet GetCompaniesSubset(
        int startRowIndex, int maximumRows, string sortExpression, bool status)
{...}

How do you allow the SelectMethod to utilise StartRowIndexParameterName/MaximumRowsParameterName and any extra parameters?

Thanks


Solution

  • The problem is that GetCompaniesCount does not have status parameter, not GetCompaniesSubset.