RadComboBox in the GridTableHeaderCell of a RadGrid

2 posts, 0 answers
  1. Doug
    Doug avatar
    3 posts
    Member since:
    Feb 2014

    Posted 04 Aug 2017 Link to this post

    Greetings, we're dynamically generating the columns and GridColumnGroups of a RadGrid in codebehind. At the point where we're adding a new column group to the MasterTableView of the RadGrid, we're establishing a specified GridColumnGroup HeaderText and Name (as a token). Then in the RadGrid ItemCreated event handler, we're detecting that the GridHeaderItem is being created...and then iterating over the TableCells in the GridHeaderItem to find the cell that starts with that token. . .and finally inserting a RadComboBox in the controls collection of that TableCell.

    This worked flawlessly until the last Telerik update. Now all that is seen is the GridHeaderItem HeaderText/Name, instead of the RadComboBox. Any assistance would be greatly appreciated. Thanks!

  2. Peter Milchev
    Peter Milchev avatar
    910 posts

    Posted 08 Aug 2017 Link to this post

    Hello Doug,

    We have investigated the scenario and it turns out the Grid is clearing the controls collection at a later stage. 

    That is why the control should be created early in the page lifecycle but should be added to the controls collection at a later stage, the PreRender event for example.

    Please find attached a sample project implementing the suggested approach.

    protected void RadGrid1_OnItemCreated(object sender, GridItemEventArgs e)
        if (e.Item is GridHeaderItem)
            var gridHeaderItem = (e.Item as GridHeaderItem);
            var cells = gridHeaderItem.Cells;
            foreach (TableCell cell in cells)
                if (cell.Text.StartsWith("Middle") && cell.Controls.Count == 0)
                    cell.Text = string.Empty;
                    cell.BackColor = Color.LightGreen;
                    var box = new RadComboBox { AutoPostBack = true, Visible = true };
                    box.Items.Add(new RadComboBoxItem("a", "b"));
                    box.SelectedValue = "b";
                    box.ID = Guid.NewGuid().ToString();
                    e.Item.PreRender += (s, a) =>

    More on anonymous functions and lambda expressions in C# could be found here: Lambda Expressions (C# Programming Guide).

    Peter Milchev
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top