This is a migrated thread and some comments may be shown as answers.

RadDataForm

1 Answer 220 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Rogelio
Top achievements
Rank 1
Rogelio asked on 06 Jan 2015, 06:22 PM
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?






1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 07 Jan 2015, 01:46 PM
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
Tags
DataForm
Asked by
Rogelio
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or