RadCombobox cascading inside RadGrid

2 posts, 0 answers
  1. Melvin
    Melvin avatar
    14 posts
    Member since:
    Apr 2015

    Posted 09 Jun 2015 Link to this post

    Hello,

     I have a problem when i work with two radcombox inside radgrid. The problem is that when the event SelectedIndexChanged is fired the second radcombox is not filled. Besides the entire form is reloaded.

     I try to put a radAjaxpanel inside label <FormTemplate> to solve this problem. But the second radcombo is not filled.

     I do not understand what is the problem.

    The code is the next

    <telerik:RadGrid runat="server" Id="rgDirecciones" AutoGenerateColumns="False" 
        OnItemDataBound="rgDirecciones_ItemDataBound"
        CellSpacing="-1" GroupPanelPosition="Top" >
        <mastertableview datakeynames="IdDireccion,IdSucursal,IdEmpresa">
            <rowindicatorcolumn visible="False">
            </rowindicatorcolumn>
            <expandcollapsecolumn created="True">
            </expandcollapsecolumn>
            <Columns>
                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"
                    EditImageUrl="../imagenes/Edit.png" InsertImageUrl="../imagenes/Edit.png" Exportable="False">
                    <HeaderStyle Width="30px" />
                </telerik:GridEditCommandColumn>                           
                <telerik:GridBoundColumn DataField="IdDireccion" UniqueName="IdDireccion" HeaderText="No Dirección">
                    <HeaderStyle Width="80px" />
                </telerik:GridBoundColumn>                                           
                <telerik:GridBoundColumn DataField="Pais" UniqueName="Pais" HeaderText="Pais">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="DivisionTerritorial" UniqueName="DivisionTerritorial" HeaderText="Division Territorial">
                </telerik:GridBoundColumn>
                <telerik:GridButtonColumn ConfirmText="Desea eliminar este registro?" ConfirmDialogType="RadWindow" ConfirmTitle="Eliminar" ButtonType="ImageButton" CommandName="Delete" ImageUrl="../imagenes/Delete.png" UniqueName="DeleteColumn" Text="Eliminar" FilterControlAltText="Filter DeleteColumn column"  Exportable="False">
                    <HeaderStyle Width="30px" />
                </telerik:GridButtonColumn>
            </Columns>
            <editformsettings editformtype="Template">
                <formtemplate>
                    <table class="table table-condensed">
                        <tr>
                            <td style="width: 150px">
                                <asp:Label ID="lbIdDireccion" runat="server" Text="No Dirección"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadNumericTextBox ID="txtIdDireccion"
                                    runat="server"
                                    Enabled="<%# (Container is GridEditFormInsertItem) ? true : false %>"
                                    MaxLength="2"
                                    MaxValue="99"
                                    MinValue="0"
                                    Text='<%# Bind("IdDireccion") %>'
                                    Width="80px">
                                    <numberformat decimaldigits="0" groupseparator="" />
                                </telerik:RadNumericTextBox>
                                <asp:RequiredFieldValidator ID="rfvIdDireccion" runat="server"
                                    ControlToValidate="txtIdDireccion" Display="Dynamic"
                                    ErrorMessage="Campo Obligatorio" ForeColor="Red">
                                </asp:RequiredFieldValidator>
                            </td>
                        </tr>                                               
                        <tr>
                            <td style="width: 150px">
                                <asp:Label ID="lbPaisDire" runat="server" Text="País"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadComboBox ID="cmbPais" Runat="server" Width="350px" Height="150px"
                                    AutoPostBack="True" OnSelectedIndexChanged="combo_SelectedIndexChanged">
                                </telerik:RadComboBox>
                                <asp:RequiredFieldValidator ID="rfvcmbPais" runat="server" 
                                    Display="Dynamic" ForeColor="Red"
                                    ControlToValidate="cmbPais" ErrorMessage="Campo Obligatorio">
                                </asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 150px">
                                <asp:Label ID="lbDivisionTerritorial" runat="server" Text="División Territorial"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadComboBox ID="cmbDivisionTerritorial" Runat="server" Width="350px">
                                </telerik:RadComboBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <telerik:RadButton ID="RadButton1" runat="server" causesvalidation="true" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' Text='<%# (Container is GridEditFormInsertItem) ? "Agregar" : "Guardar" %>' validationgroup="Textbox">
                                    <icon primaryiconurl="../imagenes/save_16x16.png" />
                                </telerik:RadButton>
                                    
                                <telerik:RadButton ID="RadButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancelar">
                                    <icon primaryiconurl="../imagenes/cancel.png" />
                                </telerik:RadButton>
                                       
                                <asp:Label ID="Label2" runat="server" CssClass="opcionales" Text="* Opcionales"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </formtemplate>
            </EditFormSettings>
            <CommandItemTemplate>
                <div class="col-xs-6">
                    <asp:LinkButton ID="lbAgregarDirecciones" runat="server" CommandName="InitInsert" Visible='<%# !rgDirecciones.MasterTableView.IsItemInserted %>'><img style="border:2px;vertical-align:middle;" alt="" src="../imagenes/AddRecord.png"/> Agregar</asp:LinkButton>  
                    <asp:LinkButton ID="lbRefrescarDirecciones" runat="server">
                        <img style="border:2px;vertical-align:middle;" alt="" src="../imagenes/Refresh.png"/> Refrescar
                    </asp:LinkButton>  
                </div>
            </CommandItemTemplate>
        </mastertableview>
    </telerik:RadGrid>

    code c # 

    protected void rgDirecciones_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridEditFormInsertItem || e.Item is GridDataInsertItem)
                {
                    GridEditFormItem editItem = (GridEditFormItem)e.Item;
     
                    //insert item
                    //Fill combobox Pais
                    Clases.MetodosGlobales.ObtenerInformacion("ADMMPaises_getCombo");
                    Clases.MetodosGlobales.LlenarComboBox("cmbPais", "Nombre", "Pais", editItem, RadComboBoxFilter.StartsWith);
                     
                }
                else
                {
                    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)editform
                    {
                        GridEditFormItem editItem = (GridEditFormItem)e.Item;
     
                         //edit item
                        RadComboBox comboPais = (RadComboBox)editItem.FindControl("cmbPais");
                        comboPais.SelectedValue = editItem["Pais"].Text;
                    }
                }
            }
     
    protected void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
                GridEditableItem editedItem = (sender as RadComboBox).NamingContainer as GridEditableItem;
                GridEditFormItem item = (sender as RadComboBox).NamingContainer as GridEditFormItem;
                RadComboBox comboPaises = sender as RadComboBox;
                RadComboBox comboDivisionTerritorial = (RadComboBox)editedItem.FindControl("cmbDivisionTerritorial");
     
                var parametrosSQL = new string[] { null, e.Value };
                DataSet ds = Clases.MetodosGlobales.ObtenerInformacionObjeto("ADMMDivisionesTerritoriales_get", parametrosSQL);
                 
                comboDivisionTerritorial.Text = null;
                comboDivisionTerritorial.EmptyMessage = "- Seleccione un valor -";
                comboDivisionTerritorial.Filter = RadComboBoxFilter.StartsWith;
                comboDivisionTerritorial.DataSource = ds.Tables[0];
                comboDivisionTerritorial.DataTextField = "Descripcion";
                comboDivisionTerritorial.DataValueField = "Divisionterritorial";
                comboDivisionTerritorial.DataBind();
            }
     

    Regards,

     

     

  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 12 Jun 2015 Link to this post

    Hi Melvin,

    I am sending two RadGrid web site samples to demonstrate implementation of cascading RadComboBoxes to edit the grid records. Please run the attached applications and let me know if they help you.

    You can also check the following section:
    ( Section Accessing controls in edit/insert mode )
    http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html


    Hope this helps.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top