Help with ObjectDataSource binding.

Discussion in 'ASP .Net' started by JDeats, Apr 1, 2009.

  1. JDeats

    JDeats Guest

    I'm trying to discover where to specify attribute mapping (not sure if
    that is the correct term as I'm trying to get my head around this
    process) for an ObjectDataSource

    My ObjectDataSource in this case is to a class called PersonData which
    has Update, Insert, Delete, Select methods. Using the Update method as
    an example. The Update method takes in three properties
    int id, string fname, string lname, int age

    Should I be following a specific naming convention on method params?
    If not how does the page compiler know how what to provide to my
    Insert method? I don't see a place to specify this or any explanation
    on the rules of how this would be inferred by the object.

    Below I'm providing a code sample of how my ObjectDataSource is
    defined and a editable DataGridView that is bound to this object. On
    update I get the following message:

    "ObjectDataSource 'ObjectDataSource1' could not find a non-generic
    method...". I assume if I could somehow tell the ObjectDataSource
    where to pull/map the UpdateMethod parameters this would go away.


    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    TypeName="PersonData" DeleteMethod="DeletePerson"
    UpdateMethod="UpdatePerson"
    InsertMethod="InsertPerson" SelectMethod="GetAllPersons">
    <DeleteParameters>
    <asp:parameter Name="id" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
    <asp:parameter Name="id" Type="Int32" />
    <asp:parameter Name="fname" Type="String" />
    <asp:parameter Name="lname" Type="String" />
    <asp:parameter Name="age" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
    <asp:parameter Name="newid" Type="Int32" />
    </InsertParameters>
    </asp:ObjectDataSource>

    <asp:GridView ID="GridView1" runat="server"
    DataSourceID="ObjectDataSource1"
    AutoGenerateColumns="False" CellPadding="4"
    ForeColor="#333333"
    GridLines="None">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <Columns>
    <asp:CommandField ShowDeleteButton="True"
    ShowEditButton="True" />
    <asp:BoundField DataField="PersonID"
    HeaderText="PersonID"
    SortExpression="PersonID" ReadOnly=false />
    <asp:BoundField DataField="FName" HeaderText="FName"
    SortExpression="FName" ReadOnly=false />
    <asp:BoundField DataField="LName" HeaderText="LName"
    SortExpression="LName" ReadOnly=false />
    <asp:BoundField DataField="Age" HeaderText="Age"
    SortExpression="Age" ReadOnly=false />
    </Columns>
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    ForeColor="#333333" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <EditRowStyle BackColor="#999999" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
     
    JDeats, Apr 1, 2009
    #1
    1. Advertising

  2. JDeats

    RMZ Guest

    On Mar 31, 6:36 pm, JDeats <> wrote:
    > I'm trying to discover where to specify attribute mapping (not sure if
    > that is the correct term as I'm trying to get my head around this
    > process) for an ObjectDataSource
    >
    > My ObjectDataSource in this case is to a class called PersonData which
    > has Update, Insert, Delete, Select methods. Using the Update method as
    > an example. The Update method takes in three properties
    >   int id, string fname, string lname, int age
    >
    > Should I be following a specific naming convention on method params?
    > If not how does the page compiler know how what to provide to my
    > Insert method? I don't see a place to specify this or any explanation
    > on the rules of how this would be inferred by the object.
    >
    > Below I'm providing a code sample of how my ObjectDataSource is
    > defined and a editable DataGridView that is bound to this object. On
    > update I get the following message:
    >
    > "ObjectDataSource 'ObjectDataSource1' could not find a non-generic
    > method...". I assume if I could somehow tell the ObjectDataSource
    > where to pull/map the UpdateMethod parameters this would go away.
    >
    >         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    >          TypeName="PersonData" DeleteMethod="DeletePerson"
    > UpdateMethod="UpdatePerson"
    >             InsertMethod="InsertPerson" SelectMethod="GetAllPersons">
    >             <DeleteParameters>
    >                 <asp:parameter Name="id" Type="Int32" />
    >             </DeleteParameters>
    >             <UpdateParameters>
    >                 <asp:parameter Name="id" Type="Int32" />
    >                 <asp:parameter Name="fname" Type="String" />
    >                 <asp:parameter Name="lname" Type="String" />
    >                 <asp:parameter Name="age" Type="Int32" />
    >             </UpdateParameters>
    >             <InsertParameters>
    >                 <asp:parameter Name="newid" Type="Int32" />
    >             </InsertParameters>
    >         </asp:ObjectDataSource>
    >
    >   <asp:GridView ID="GridView1" runat="server"
    > DataSourceID="ObjectDataSource1"
    >         AutoGenerateColumns="False" CellPadding="4"
    > ForeColor="#333333"
    >         GridLines="None">
    >         <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="White" />
    >         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    >         <Columns>
    >             <asp:CommandField ShowDeleteButton="True"
    > ShowEditButton="True" />
    >             <asp:BoundField DataField="PersonID"
    > HeaderText="PersonID"
    >                 SortExpression="PersonID" ReadOnly=false />
    >             <asp:BoundField DataField="FName" HeaderText="FName"
    > SortExpression="FName" ReadOnly=false />
    >             <asp:BoundField DataField="LName" HeaderText="LName"
    > SortExpression="LName" ReadOnly=false />
    >             <asp:BoundField DataField="Age" HeaderText="Age"
    > SortExpression="Age" ReadOnly=false />
    >         </Columns>
    >         <PagerStyle BackColor="#284775" ForeColor="White"
    > HorizontalAlign="Center" />
    >         <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    > ForeColor="#333333" />
    >         <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="White" />
    >         <EditRowStyle BackColor="#999999" />
    >         <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    >     </asp:GridView>



    I found my answer and wanted to post it for others who might be
    searching this group at a future date. The answer is that the
    parameter names are inferred the input method parameter variable names
    must match the variables names of the object returned by the
    SelectMethod.

    So in my case for example, my Update method inside my bound custom
    data object looked had this method signature

    public UpdatePerson(int id, string fname, string lname, int age)

    I had to change that to:
    public UpdatePerson(int PersonID, string FName, string LName, int Age)

    and for delete i had

    public DeletePerson(int id)

    which had to be changed to

    public DeletePerson(int PersonID)

    now everything is resolving as it should... I hope this helps someone
    in the future.
     
    RMZ, Apr 1, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    6,970
    Guest
    Jun 28, 2005
  2. GaryDean
    Replies:
    3
    Views:
    9,568
    Luke Zhang [MSFT]
    Jan 10, 2006
  3. H5N1
    Replies:
    0
    Views:
    484
  4. John Davis
    Replies:
    0
    Views:
    408
    John Davis
    Aug 30, 2006
  5. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    250
    Steven Cheng[MSFT]
    Mar 23, 2006
Loading...

Share This Page