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

RadCombobox cascading inside RadGrid

3 Answers 779 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Melvin
Top achievements
Rank 1
Melvin asked on 09 Jun 2015, 02:20 PM

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,

 

 

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 Jun 2015, 01:20 PM
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
0
Bernie
Top achievements
Rank 1
answered on 06 May 2019, 02:46 PM

Thank you so much for these examples. I can now "see" a clear path to where I need to be. I didn't write back on Friday because I wanted to fix this myself, but I'm stuck. Attached is my simple page. I'm setting up one column as a GridTemplateColumn as a start. I included a ComboBox and set the ComboBox.OnDataBinding. My problem is the combobox doesn't show on the edit or insert modes.

The release column is populated in the grid view, but selecting Edit or New doesn't show the combobox.

What am I missing here?

Bernie

 

protected void grdData_OnItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
 
        // load the employees ...
        GridDropDownListColumnEditor employeeEditor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("Employee"));  // uniquename of the column ...
        RadComboBox theBox = employeeEditor.ComboBoxControl;
        clsUtilities.LoadEmployees(theBox);
 
        // load the jobs ...
        GridDropDownListColumnEditor jobEditor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("Job"));
        RadComboBox theJobBox = jobEditor.ComboBoxControl;
        clsUtilities.LoadTheActiveJobs(theJobBox);
 
        // next ...
 
        // next ...
 
    }    // if ...
}    // grdData_OnItemDataBound() ...
 
protected void rcbRelease_OnDataBinding(object sender, EventArgs e)
{
    RadComboBox theRCB = sender as RadComboBox;
 
    DataClassesDataContext db = new DataClassesDataContext("mySQLServer");
    db.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["mySQLServer"].ToString();
 
    var releases = from r in db.a_Releases
                   where r.TopLevelJob == "A2552013"
                   orderby r.Name
                   select new { r.Name };
 
    foreach (var release in releases)
    {
        theRCB.Items.Add(new RadComboBoxItem(release.Name, release.Name));
    }
}    // rcbRelease_OnDataBinding() ...
 
protected void LoadTheGrid()
{
    DataClassesDataContext db = new DataClassesDataContext("mySQLServer");
    db.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["mySQLServer"].ToString();
 
    var theDatas = from t in db.a_Tasks
                   where t.Supervisor == rcbSupervisor.SelectedValue
                        || t.Department == rcbDepartment.SelectedValue
                   select new
                   {
                       t.TID,
                       t.Supervisor,
                       t.Department,
                       t.Employee,
                       t.Job,
                       t.ComponentJob,
                       t.Release,
                       t.Operation,
                       t.Quantity,
                       t.Priority,
                       t.Status,
                       LastEdit = t.LastEdit.ToShortDateString()
                   };
 
    grdData.DataSource = theDatas;
}    // LoadTheGrid() ...

 

    <asp:UpdatePanel ID="pnlEdit" runat="server">
        <ContentTemplate>
            <h1>Kinemotive Task Assignments</h1>
            Supervisor:
            <telerik:RadComboBox ID="rcbSupervisor" runat="server"
                MarkFirstMatch="true"
                AutoPostBack="True"
                OnSelectedIndexChanged="rcbSupervisor_OnSelectedIndexChanged" >
            </telerik:RadComboBox>
            Department:
            <telerik:RadComboBox ID="rcbDepartment" runat="server"
                 MarkFirstMatch="true" OnSelectedIndexChanged="rcbDepartment_OnSelectedIndexChanged" >
            </telerik:RadComboBox>
            <br />
            <telerik:RadGrid RenderMode="Lightweight" ID="grdData" runat="server"
                    OnNeedDataSource="grdData_OnNeededDataSource" OnItemDataBound="grdData_OnItemDataBound" >
                <MasterTableView Width="100%"
                        DataKeyNames="TID"
                        EditMode="EditForms"
                        AutoGenerateColumns="false"
                        InsertItemDisplay="Top"
                        CommandItemDisplay="Top"
                        InsertItemPageIndexAction="ShowItemOnFirstPage">
                    <Columns>
                        <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="TID" UniqueName="TID"
                            HeaderText="TID" ReadOnly="true"></telerik:GridBoundColumn>
                        <telerik:GridDropDownColumn UniqueName="Employee" ListDataMember="Employee"
                            SortExpression="Employee" ListTextField="Employee" ListValueField="Employee"
                            HeaderText="Employee" DataField="Employee"
                            DropDownControlType="RadComboBox"
                            EnableEmptyListItem="true" EmptyListItemText="Make a choice" EmptyListItemValue=""
                            />
                        <telerik:GridDropDownColumn UniqueName="Job" ListDataMember="Job"
                            SortExpression="Job" ListTextField="Job" ListValueField="Job"
                            HeaderText="Job" DataField="Job"
                            DropDownControlType="RadComboBox"
                            EnableEmptyListItem="true" EmptyListItemText="Make a choice" EmptyListItemValue=""
                            />
                        <telerik:GridTemplateColumn UniqueName="Release"
                                HeaderText="Release"
                                HeaderStyle-HorizontalAlign="Center"
                                SortExpression="Release"
                                ItemStyle-Width="170px" HeaderStyle-Width="80px"
                                DataField="Release" >
                            <ItemTemplate>
                                <%#DataBinder.Eval(Container.DataItem, "Release")%>
                            </ItemTemplate>
                         
                            <telerik:EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="rcbRelease"
                                    AutoPostBack="true"
                                    EnableLoadOnDemand="true"
                                    DataTextField="Release"
                                    DataValueField="Release"
                                    Text='<% #Bind("Release")%>'
                                    EnableEmptyListItem="true"
                                    EmptyListItemText="Make a choice"
                                    EmptyListItemValue="NR"
                                    OnDataBinding="rcbRelease_OnDataBinding"
                                    >
                                </telerik:RadComboBox>
                             
                            </telerik:EditItemTemplate>
                         
                         
                        </telerik:GridTemplateColumn>
 
 
<%--                        <telerik:GridBoundColumn DataField="Release" HeaderText="Release" ></telerik:GridBoundColumn>--%>
 
                        <telerik:GridBoundColumn DataField="ComponentJob" UniqueName="ComponentJob" HeaderText="ComponentJob"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Operation" UniqueName="Operation" HeaderText="Operation"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Quantity" UniqueName="Quantity" HeaderText="Quantity"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Priority" UniqueName="Priority" HeaderText="Priority"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Status" UniqueName="Status" HeaderText="Status"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="LastEdit" UniqueName="LastEdit" HeaderText="LastEdit"></telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </ContentTemplate>
    </asp:UpdatePanel>

 

 

0
Eyup
Telerik team
answered on 09 May 2019, 05:00 AM
Hello Bernie,

I've answered in the formal support ticket about this matter. You can send us a sample there so we can continue with bringing this case to a resolution.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Melvin
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Bernie
Top achievements
Rank 1
Share this question
or