A
anyeone
I've got a GridView bound to an Object Data Source and I'm having trouble
figuring out just how to set it up to update properly.
I have the object data source defined as so:
<asp:ObjectDataSource ID="objBatchData" runat="server"
SelectMethod="GetItems" TypeName="MyNamespace.BatchData"
DataObjectTypeName="MyNamespace.BatchItem" UpdateMethod="UpdateItem" >
<SelectParameters>
<asp:QueryStringParameter Name="BatchID" QueryStringField="BatchID"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asparameter Name="ItemID" Type="Int32" />
<asparameter Name="BatchID" Type="Int32" />
<asparameter Name="DataField1" Type="string" />
<asparameter Name="DataField2" Type="string" />
</UpdateParameters>
</asp:ObjectDataSource>
..
BatchItem is a business object that defines several constructors. The
BatchItem(DataRow row) constructor is the one that GetItems() uses to
instantiate individual BatchItems when the object data source binding occurs.
There is also a BatchItem(int ItemID) constructor and a default constructor
that doesn't actually do anything.
ItemID and BatchID are read only and brought in through BatchItem on the
original select statement. DataField1 and 2 are the two fields actually
being updated by the user through dropdownlists bound to BatchItem.DataList1
and BatchItem.DataList2 respectively
The static BatchData.GetItems method seems to be working properly as the
grid is being populated with the correct data.
The static BatchData.UpdateItem method takes in a BatchItem object (since I
got an error when I defined it to explicitly take in ItemID, BatchID,
DataField1, DataField2 saying it needed to take in a BatchItem as a
parameter). It then creates a collection of SqlParameters and calls a stored
proc to perform the update.
The problem is, when the row is updated, the application is instantiating a
default constructor version of BatchItem which is empty and passing that to
BatchData.UpdateItem().
So what I need to figure out is how to get the data from the GridView row
being updated (the four properties listed in "UpdateParameters" on the object
data source) into the BatchItem that is passed to BatchData.UpdateItem().
I've been using some of Phillip Williams' examples to model from (if you're
listening, Phillip), particularly the "DropdownList within a GridView"
example and where I see a disconnect is that the UpdateParameters don't seem
to be tied to anything in the grid data particularly. Unfortunately without
being able to view the source of his UpdateOrder method (the UpdateMethod on
his object data source) I can't compare what I'm doing to what he is doing to
see the problem.
Am I supposed to be overriding one of the GridView events to stuff a
ConfirmItem object with the correct field data? The UpdateItem method only
takes ConfirmItem so I don't seem to have access to a parameters collection.
Help is greatly appreciated, thanks! If you need more information please
let me know.
figuring out just how to set it up to update properly.
I have the object data source defined as so:
<asp:ObjectDataSource ID="objBatchData" runat="server"
SelectMethod="GetItems" TypeName="MyNamespace.BatchData"
DataObjectTypeName="MyNamespace.BatchItem" UpdateMethod="UpdateItem" >
<SelectParameters>
<asp:QueryStringParameter Name="BatchID" QueryStringField="BatchID"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asparameter Name="ItemID" Type="Int32" />
<asparameter Name="BatchID" Type="Int32" />
<asparameter Name="DataField1" Type="string" />
<asparameter Name="DataField2" Type="string" />
</UpdateParameters>
</asp:ObjectDataSource>
..
BatchItem is a business object that defines several constructors. The
BatchItem(DataRow row) constructor is the one that GetItems() uses to
instantiate individual BatchItems when the object data source binding occurs.
There is also a BatchItem(int ItemID) constructor and a default constructor
that doesn't actually do anything.
ItemID and BatchID are read only and brought in through BatchItem on the
original select statement. DataField1 and 2 are the two fields actually
being updated by the user through dropdownlists bound to BatchItem.DataList1
and BatchItem.DataList2 respectively
The static BatchData.GetItems method seems to be working properly as the
grid is being populated with the correct data.
The static BatchData.UpdateItem method takes in a BatchItem object (since I
got an error when I defined it to explicitly take in ItemID, BatchID,
DataField1, DataField2 saying it needed to take in a BatchItem as a
parameter). It then creates a collection of SqlParameters and calls a stored
proc to perform the update.
The problem is, when the row is updated, the application is instantiating a
default constructor version of BatchItem which is empty and passing that to
BatchData.UpdateItem().
So what I need to figure out is how to get the data from the GridView row
being updated (the four properties listed in "UpdateParameters" on the object
data source) into the BatchItem that is passed to BatchData.UpdateItem().
I've been using some of Phillip Williams' examples to model from (if you're
listening, Phillip), particularly the "DropdownList within a GridView"
example and where I see a disconnect is that the UpdateParameters don't seem
to be tied to anything in the grid data particularly. Unfortunately without
being able to view the source of his UpdateOrder method (the UpdateMethod on
his object data source) I can't compare what I'm doing to what he is doing to
see the problem.
Am I supposed to be overriding one of the GridView events to stuff a
ConfirmItem object with the correct field data? The UpdateItem method only
takes ConfirmItem so I don't seem to have access to a parameters collection.
Help is greatly appreciated, thanks! If you need more information please
let me know.