Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help with ObjectDataSource binding.

Reply
Thread Tools

Help with ObjectDataSource binding.

 
 
JDeats
Guest
Posts: n/a
 
      03-31-2009
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>
<asparameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="id" Type="Int32" />
<asparameter Name="fname" Type="String" />
<asparameter Name="lname" Type="String" />
<asparameter Name="age" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter 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>

 
Reply With Quote
 
 
 
 
RMZ
Guest
Posts: n/a
 
      04-01-2009
On Mar 31, 6:36*pm, JDeats <(E-Mail Removed)> 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>
> * * * * * * * * <asparameter Name="id" Type="Int32" />
> * * * * * * </DeleteParameters>
> * * * * * * <UpdateParameters>
> * * * * * * * * <asparameter Name="id" Type="Int32" />
> * * * * * * * * <asparameter Name="fname" Type="String" />
> * * * * * * * * <asparameter Name="lname" Type="String" />
> * * * * * * * * <asparameter Name="age" Type="Int32" />
> * * * * * * </UpdateParameters>
> * * * * * * <InsertParameters>
> * * * * * * * * <asparameter 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving SqlDataSource to ObjectDataSource. need help Raja ASP .Net 2 03-14-2008 09:12 PM
checkboxlist inside a formview databind with objectdatasource(Please somebody help me) Jai ASP .Net 0 09-25-2006 01:18 PM
Help w/ ObjectDataSource fingermark@gmail.com ASP .Net 2 09-08-2006 07:09 PM
ObjectDataSource method as another ObjectDataSource David Thielen ASP .Net Web Controls 3 03-23-2006 01:50 AM
HELP !!! ObjectDataSource Delete Parameter Problem ASP.NET 2.0 Microsoft news ASP .Net 2 03-16-2005 05:37 PM



Advertisments