RadPanelItem.DataItem is null on DataBind within FormView

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    1 posts
    Member since:
    Mar 2011

    Posted 04 Jan 2013 Link to this post

    I have a FormView hooked into an ObjectDataSource.  Inside the FormView sits a RadPanelBar.  I have some databound controls within the RadPanelBar and I've had a terrible time getting them to work.

    First, I used the suggested method, DataBinder.Eval(FormView1.DataItem, "BillingDate").  This causes the FormView to have an empty oldValues and newValues collection when it updates.  That took me days to figure out.

    I then tried an alternative method, strongly typing the DataItem from the container.  

                                (Container.DataItem ?? new Wcsr.ProjectBilling.Business.Data.ProjectTask())).Code

    I am getting a null DataItem here.  If I use FormView1.DataItem, the oldValues and newValues collections become empty again.  What can I do?

    <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Edit" OnItemUpdated="FormView1_ItemUpdated" OnItemUpdating="FormView1_ItemUpdating">
            <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Metro" Width="100%">
                    <telerik:RadPanelItem runat="server" Expanded="True" PreventCollapse="True" Text="Basic Task Information">
                                <asp:Label ID="Label1" runat="server" CssClass="fieldLabel">Task Code</asp:Label>
                                <%-- For some reason RadPanelItem requires you to do databinding with DataBinder.Eval --%>
                                <asp:TextBox ID="TaskCodeTb" runat="server" MaxLength="20" Text='<%# ((Wcsr.ProjectBilling.Business.Data.ProjectTask)
                                (Container.DataItem ?? new Wcsr.ProjectBilling.Business.Data.ProjectTask())).Code %>'></asp:TextBox>
                                <asp:Label ID="Label4" runat="server" CssClass="fieldLabel">Task Description</asp:Label>
                                <asp:TextBox ID="DescriptionTb" runat="server" MaxLength="250" Rows="3" Text='<%# ((Wcsr.ProjectBilling.Business.Data.ProjectTask)
                                (Container.DataItem ?? new Wcsr.ProjectBilling.Business.Data.ProjectTask())).Description %>' TextMode="MultiLine"></asp:TextBox>
            <asp:LinkButton runat="server" ID="UpdateLb" Text="Update" CommandName="Update"></asp:LinkButton
            <asp:LinkButton runat="server" ID="CancelLb" Text="Cancel" CommandName="Cancel"></asp:LinkButton>
  2. Kate
    Kate avatar
    1898 posts

    Posted 17 Jan 2013 Link to this post

    Hi Andrew,

    I will paste my answer from the ticket here as well in case anyone else encounter the same issue:

    I prepared a very simplified runnable project that I believe complies with the scenario that you are trying to achieve. Please download the attached project, run it and let me know if this is the desired effect.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top