Hi Polita,
Thank you very much for your response. It did not solve my problem entirely but gave me enough of a pointer to realize that the problem I have is not related to the ObjectDataSource, is is actually to do with the way I am creating my GridView control. What I am trying to do is that I am trying to programatically create templated columns within my GridView control. Here is the code:
Private Sub GridView1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Init
InitialiseColumns()
End Sub
Private
Sub InitialiseColumns()
'This collection gets set somewhere else that gets used here
If IoColumns IsNot Nothing Then
For Each LoSetting In IoColumns
Dim LoTemplate As New TemplateField
LoTemplate.HeaderTemplate =
New LabelTemplate(DataControlRowType.Header, LoSetting.ColumnHeading)
LoTemplate.ItemTemplate =
New LabelTemplate(DataControlRowType.DataRow, LoSetting.DataColumnName)
LoTemplate.EditItemTemplate =
New TextBoxTemplate(LoSetting.DataColumnName)
GridView1.Columns.Add(LoTemplate)
Next
End If
End Sub
This displays data correctley in the GridView both in normal as well as edit mode. When I try to update the row currently in edit mode, the row comes back with an empty new values collection.
If I do the same thing with the same data source and same columns in declarative fashion, every thing works fine and the new values get returned without any problem. Just as a reference, I am pasting the declarative code below.
<asp:GridView runat="server" DataSourceID="ObjectDatasource1"
ID="GridView1"
AllowSorting="True"
EmptyDataText="No records were returned."
AutoGenerateColumns="False"
AllowPaging="True">
<Columns>
<asp:CommandField ShowEditButton="true" />
<asp:BoundField DataField="RowKey" HeaderText="RowKey" SortExpression="RowKey" />
<asp:BoundField DataField="ChargeableRate" HeaderText="ChargeableRate" SortExpression="ChargeableRate" />
<asp:BoundField DataField="Gridrowid" HeaderText="Gridrowid" SortExpression="Gridrowid" />
<asp:BoundField DataField="ContactPhone" HeaderText="ContactPhone" SortExpression="ContactPhone" />
<asp:BoundField DataField="StandardRate" HeaderText="StandardRate" SortExpression="StandardRate" />
<asp:BoundField DataField="ParentKey" HeaderText="ParentKey" SortExpression="ParentKey" />
<asp:BoundField DataField="HearAboutUs" HeaderText="HearAboutUs" SortExpression="HearAboutUs" />
<asp:BoundField DataField="WhoModified" HeaderText="WhoModified" SortExpression="WhoModified" />
<asp:BoundField DataField="BookingReference" HeaderText="BookingReference" SortExpression="BookingReference" />
<asp:BoundField DataField="DateModified" HeaderText="DateModified" SortExpression="DateModified" />
<asp:BoundField DataField="ConsentReceived" HeaderText="ConsentReceived" SortExpression="ConsentReceived" />
<asp:BoundField DataField="Organisation" HeaderText="Organisation" SortExpression="Organisation" />
<asp:BoundField DataField="ContactPerson" HeaderText="ContactPerson" SortExpression="ContactPerson" />
<asp:BoundField DataField="WhoCreated" HeaderText="WhoCreated" SortExpression="WhoCreated" />
<asp:BoundField DataField="AwareOfCost" HeaderText="AwareOfCost" SortExpression="AwareOfCost" />
</Columns>
</
asp:GridView>
<
asp:ObjectDataSource runat="server"
SelectCountMethod="GetAllCount"
DeleteMethod="Delete"
SortParameterName="sortExpression"
SelectMethod="GetAll"
ID="ObjectDatasource1"
EnablePaging="True" UpdateMethod="UpdateRow"
OldValuesParameterFormatString="original_{0}"
InsertMethod="Insert" DataObjectTypeName="YouthsafeTest.YsPresentation" TypeName="YouthsafeTest.YsPresentation" >
</
asp:ObjectDataSource>
There might be something very simple that I am missing here, but it is driving me completely crazy at the moment. I would greatly appreciate if you could help me in this regard.
Thanks
Muzaffar