Question

The Problem: An ObjectDataSource is sending over a (basically) empty data object when calling the update method by means of a FormView. The only fields with values are fields listed in the FormView's DataKeyNames property.

Note: I am using Telerik RadPanelBars within the FormView.

When I break on the FormView's ItemUpdating event, I see that:

  • The Keys list has two items, just like the DataKeyNames property. That looks good.
  • The OldValues and NewValues dictionaries are empty. They don't have anything in them. Not field names with null values - they are literally empty lists with zero items.

When we get to the ObjectDataSource's Updating event, we see a ProjectTask object with just two values (matching the DataKeyNames fields) - all other fields are null.

Here is the update method I'm using:

    public static void UpdateProjectTask(ProjectTask projectTask)
    {
        var dc = new PrbDataContext();
        dc.ProjectTasks.Attach(projectTask, true);
        dc.SubmitChanges();
    }

Here's the markup for the ObjectDataSource and FormView:

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="ProjectBilling.Business.Data.ProjectTask"
        SelectMethod="GetProjectTask" TypeName="ProjectBilling.Business.Data.ProjectTask" UpdateMethod="UpdateProjectTask" OldValuesParameterFormatString="original_{0}" OnUpdating="ObjectDataSource1_Updating">
        <SelectParameters>
            <asp:Parameter DefaultValue="0" Name="projectTaskId" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Edit"
        DataKeyNames="Id,Timestamp" OnItemUpdated="FormView1_ItemUpdated" Width="600px">

Important: I'm using Telerik controls and they require an odd binding.

    DataBinder.Eval(FormView1.DataItem, "TaskTemplateId")

I also tried this method, which didn't yield any better results:

    ((ProjectBilling.Business.Data.ProjectTask)(Container.DataItem ?? new ProjectBilling.Business.Data.ProjectTask())).BillNarrative

The control is retrieving data just fine; I just can't update it.

Thanks as always for your help, gentlemen.

This fellow seems to be having a similar problem: Can’t get FormView values from ObjectDataSource on update

Was it helpful?

Solution

Telerik's RadPanelBar does not support databinding in markup. That is what is causing the empy OldValues and NewValues collections.

Note: Leaving this question up here because it took me forever to figure this out and there is very little on the interwebs about it. Telerik support finally had to own up to the fact that databinding doesn't work within RadPanelBar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top