RadDataForm

2 posts, 1 answers
  1. Rogelio
    Rogelio avatar
    5 posts
    Member since:
    Oct 2012

    Posted 06 Jan 2015 Link to this post

    I have a RadDataForm:
     
            <telerik:RadDataForm runat="server" ID="RadDataForm1"
                DataKeyNames="IdCompra"
                DataSourceID="dsCompraDivisasEncabezado"
                Skin="Windows7"
                OnDataBound="RadDataForm1_DataBound"
                OnItemInserting="RadDataForm1_ItemInserting"
            >

                <EditItemTemplate>
                    <fieldset class="rdfFieldset rdfBorders" style="width:550px;">
                        <legend class="rdfLegend">Compra de Divisas</legend>
                        <div class="rdfRow">
                            <asp:Label ID="lblIdCompania" runat="server" CssClass="rdfLabel rdfBlock" Text="Id Compañia:"></asp:Label>
                            <telerik:RadComboBox runat="server" ID="rcbCompania" 
                                DataSourceID="dsCompanias" 
                                DataTextField="CompaniaDescripcion"
                                DataValueField="IdCompania" 
                                AutoPostBack="true"
                                OnSelectedIndexChanged="rcbCompania_SelectedIndexChanged">
                            </telerik:RadComboBox>
                        </div>

                        <div class="rdfRow">
                            <asp:Label ID="lblIdPlanta" runat="server" CssClass="rdfLabel rdfBlock" Text="Planta:"></asp:Label>
                            <asp:Label ID="lblIdPlantaValor" runat="server" CssClass="rdfFieldValue" Text='<%# String.Concat(Eval("IdPlanta"), " - ",Eval("PlantaDescripcion"))%>' />
                        </div>
                    </fieldset>
                </EditItemTemplate>

                <InsertItemTemplate>
                    <fieldset class="rdfFieldset rdfBorders" style="width:550px;">
                        <legend class="rdfLegend">Compra de Divisas</legend>
                        <div class="rdfRow">
                            <asp:Label ID="lblIdCompania" runat="server" CssClass="rdfLabel rdfBlock" Text="Id Compañia:"></asp:Label>
                            <telerik:RadComboBox runat="server" ID="rcbCompania" 
                                DataSourceID="dsCompanias" 
                                DataTextField="CompaniaDescripcion"
                                DataValueField="IdCompania" 
                                AutoPostBack="true"
                                OnSelectedIndexChanged="rcbCompania_SelectedIndexChanged">
                            </telerik:RadComboBox>
                        </div>

                        <div class="rdfRow">
                            <asp:Label ID="lblIdPlanta" runat="server" CssClass="rdfLabel rdfBlock" Text="Planta:"></asp:Label>
                            <asp:Label ID="lblIdPlantaValor" runat="server" CssClass="rdfFieldValue" Text='<%# String.Concat(Eval("IdPlanta"), " - ",Eval("PlantaDescripcion"))%>' />
                        </div>
                    </fieldset>
                </InsertItemTemplate>

    The next procedure works when RadDataForm is in edit mode:

    protected void rcbCompania_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

            {
                RadComboBox rcbCompania = (RadComboBox)sender;
                Label lblIdPlantaValor = (Label)RadDataForm1.Items[0].FindControl("lblIdPlantaValor");

                string strMensaje = "";
                DataTable dtCompania = CompaniaConsulta("Divisas", "ID", rcbCompania.SelectedValue, out strMensaje);

                lblIdPlantaValor.Text = dtCompania.Rows[0]["IdPlanta"].ToString() + "-" + dtCompania.Rows[0]["PlantaDescripcion"].ToString();
            } but when it is in Insert mode it says: RadDataForm1.Items.Count = 0.  How can i find the control?






  2. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 07 Jan 2015 Link to this post

    Hello Rogelio,

    Can you please refer to the answer in the support ticket that you have opened regarding the same issue: Ticket ID: 894222:

    "When you initiate an insert, as you have noticed, there will be no items in the Items collection of the RadDataForm and you should use the InsertItem instead for calling the FindControl method. You can use the following code for handling both scenarios - the edit and insert:
    Label lblIdPlantaValor;
    if (RadDataForm1.Items.Count > 0)
    {
        lblIdPlantaValor = (Label)RadDataForm1.Items[0].FindControl("lblIdPlantaValor");  
    }
    else
    {
        lblIdPlantaValor = (Label)RadDataForm1.InsertItem.FindControl("lblIdPlantaValor");
    }

    If you have any further questions, I would suggest that we continue to conversation in the support ticket.


    Regards,
    Konstantin Dikov
    Telerik
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top