3

I am trying to use the ObjectDataSource with enabled paging. This requires me to use the SelectCountMethod (so the grid can know how many pages there are). My ObjectDataSource looks like this:

<asp:ObjectDataSource ID="ItemsDataSource" runat="server" SelectMethod="GetContentGridItems" 
TypeName="ContentItemExtensions" SelectCountMethod="GetContentGridItemsCount" EnablePaging="True">

<SelectParameters>
    <asp:QueryStringParameter Name="contentItemID" QueryStringField="cid" DbType="Guid" />
    <asp:QueryStringParameter Name="contentTypeID" QueryStringField="tid" Type="String" />
    <asp:QueryStringParameter Name="contentTypeGroup" QueryStringField="tgid" Type="String" />
    <asp:QueryStringParameter Name="parentItemID" QueryStringField="pcid" DbType="Guid" />
    <asp:QueryStringParameter Name="parentFieldID" QueryStringField="pfld" type="String" />
</SelectParameters>    

And the corresponding static class looks like this:

public static class ContentItemExtensions
{
    public static DataTable GetContentGridItems(Guid? contentItemId,string contentTypeID, string contentTypeGroup, Guid? parentItemID, string parentFieldID,int maximumRows, int startRowIndex)  
    public static int GetContentGridItemsCount(Guid? contentItemId,string contentTypeID, string contentTypeGroup, Guid? parentItemID, string parentFieldID)
}

All is working fine when I don't use paging but when I enable paging I get the following exception which clearly states what it needs:

ObjectDataSource 'ItemsDataSource' could not find a non-generic method 'GetContentGridItemsCount' that has parameters: contentItemID, contentTypeID, contentTypeGroup, parentItemID, parentFieldID.

My method has these parameter and is non generic so I don't have a clue. Can anyone help me?

Gluip
  • 2,917
  • 4
  • 37
  • 46

1 Answers1

5

Your method does not take the same parameters because parameter names are case-sensitive:

public static int GetContentGridItemsCount(Guid? contentItemId,
    string contentTypeId, string contentTypeGroup,
    Guid? parentItemID, string parentFieldID)
{
}

Is not the same as:

public static int GetContentGridItemsCount(Guid? contentItemID,
    string contentTypeID, string contentTypeGroup,
    Guid? parentItemID, string parentFieldID)
{
}

The names of the first two arguments have to end with a uppercase D in order to match the method signature ObjectDataSource is looking for.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • You're right! Funny thing is that it was also wrong in my GetContentGridItems method but the datasource did not have a problem with that! Inconsistent API..thanks a lot! I will accept this answer asap – Gluip Apr 06 '12 at 10:03
  • OUCH! This is a *really* nasty inconsistency. I had the exact same issue, right down to it working for the `SelectMethod` but not for `SelectCountMethod`. I freely admit that I was wrong by not matching case to start with but once it worked for select my brain classified that as correct so I copy/pasted from the select method and all of a sudden it doesn't work. Anyway, *great catch* and thanks for the post... – Lucas Sep 26 '12 at 02:34
  • Interesting - I've just been hit by the same thing in VB.NET (which isn't a case sensitive language like C# is). – Dan Nov 14 '12 at 09:49
  • Dito Lucas. This just cost me 2 hours - I hope MS are aware and looking to correct this inconsistency, as when both methods have an identical parameter list but only one complains it's hard to see why. – JGreasley Apr 19 '13 at 12:37