RadGrid Column FilterTemplate as combobox with Auto Generated Columns

4 posts, 1 answers
  1. Majd
    Majd avatar
    1 posts
    Member since:
    Feb 2012

    Posted 15 Sep 2014 Link to this post

    I have a RadGrid where the columns are autogenerated based on the DataSet.  I need to check if one of the columns exists, I would like to make that column filtered by a combobox or a dropdown.I have a RadGrid where the columns are autogenerated based on the DataSet.  I need to check if one of the columns exists, I would like to make that column filtered by a combobox or a dropdown.I have a RadGrid where the columns are autogenerated based on the DataSet.  I need to check if one of the columns exists, I would like to make that column filtered by a combobox or a dropdown.

    <telerik:RadGrid ID="rgApplications" runat="server" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True" GridLines="None" Width="100%" CellSpacing="0">
        <MasterTableView DataKeyNames="ExecutedDocumentId,TemplateId,ParentId" ClientDataKeyNames="ExecutedDocumentId,TemplateId,ParentId" AutoGenerateColumns="true" AllowFilteringByColumn="true">
            <EditFormSettings EditFormType="Template">
                <EditColumn UniqueName="EditColumn">
                    <div style="padding-bottom: 5px; padding-top: 5px; padding-left: 20px;">
                        <b><%# (Container is GridEditFormInsertItem) ? GetResource("Add") : GetResource("Edit") %></b>
                        <table border="0" cellpadding="2" width="100%">
                                <td nowrap>
                                    <asp:Label ID="lblType" runat="server" resourcekey="Type" AssociatedControlID="ddlType" />:
                                <td nowrap align="left" style="padding-left: 5px">
                                    <asp:DropDownList ID="ddlType" Width="340px" MaxLength="120" runat="server" />
                                    <span style="color: Red; padding-left: 2px; padding-right: 3px; font-size: larger">*</span>
                                    <asp:RequiredFieldValidator ID="rfvType" ControlToValidate="ddlType" InitialValue="0"
                                        ValidationGroup="UpdateApplications" runat="server" ErrorMessage="Required" ForeColor="Red" />
                            <asp:ImageButton ID="btnSaveApplications" runat="server" ValidationGroup="UpdateApplications" resourcekey="Save" CommandName="SaveApplication" />
                            <asp:ImageButton ID="btnCancelApplications" runat="server" resourcekey="Cancel" CommandName="Cancel" />
            <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="true" />
                <telerik:GridClientSelectColumn UniqueName="SelectApplication" HeaderTooltip="Select All" />
                <telerik:GridButtonColumn UniqueName="DeleteDocument" CommandName="DeleteDocument" ButtonType="ImageButton" ShowFilterIcon="false" />
                <telerik:GridButtonColumn UniqueName="ViewDocument" CommandName="ViewDocument" ButtonType="ImageButton" ShowFilterIcon="false" />

    Code Behind
    void rgApplications_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        // Make Document Status Filter A DropDown
        if (e.Column.UniqueName == "DocumentStatus")
            GridBoundColumn bCol = e.Column as GridBoundColumn;
            if (bCol != null)
                Data.TaxonomyFilteringTemplate template = new MyFilteringTemplate(e.Column.UniqueName, "Document Status", rgApplications);
                bCol.FilterTemplate = template;
                bCol.CurrentFilterFunction = GridKnownFunction.EqualTo;

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    namespace MyTestProgram
        public class MyFilteringTemplate : ITemplate
            protected DropDownList combo;
            private string colname;
            private string lookupName;
            RadGrid radgrid;
            public TaxonomyFilteringTemplate(string cName, string lookup, RadGrid grid)
                colname = cName;
                lookupName = lookup;
                radgrid = grid;
            public void InstantiateIn(Control container)
                combo = new DropDownList();
                combo.ID = "RadComboBoxControl";
                combo.AutoPostBack = true;
                //combo.EnableViewState = false;
                combo.SelectedIndexChanged += combo_SelectedIndexChanged;
                combo.Items.Add(new ListItem("Please Select"));
                var dt = MyController.GetLookupList(this.lookupName);
                var dvOptions = new DataView(dt);
                dvOptions.Sort = "Name";
                foreach (DataRow dr in dvOptions.ToTable().Rows)
                    combo.Items.Add(new ListItem(dr["Name"].ToString()));
            void combo_SelectedIndexChanged(object sender, EventArgs e)
                DropDownList ddl = sender as DropDownList;
                string filterExpression = string.Empty;
                if (ddl.Text != "")
                    filterExpression = "([" + colname + "] = '" + ddl.Text + "')";
                radgrid.MasterTableView.FilterExpression = filterExpression;

    The problem I am having is that I am getting an exception:

    Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.

    Any suggestion on how to solve this?
  2. Answer
    Eyup avatar
    3013 posts

    Posted 18 Sep 2014 Link to this post

    Hi Majd,

    I've already replied to your query in ticket with ID: 859819. I suggest that we continue our conversation on the mentioned thread should you come upon any difficulties or have further questions.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Maurizio Piaggio
    Maurizio Piaggio avatar
    13 posts
    Member since:
    May 2007

    Posted 11 Aug 2015 in reply to Eyup Link to this post

    Hi Eyup,

    could you please also post here the correct solution?

    Would be intersting to know which are the correct steps​: in my ​scenario I should have a multiple choice filter based on the autogenerated column's values, to filter the column itself ​(DropDownTree with checkboxes? Simple dropdown with multiple values?)

  5. Eyup
    Eyup avatar
    3013 posts

    Posted 14 Aug 2015 Link to this post

    Hi Simone,

    You can find the sample here - web site number 2:

    I hope it will prove helpful. You can also examine the other samples.

    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
Back to Top