Accessing RadComboBox Inside RadGrid FilterTemplate

4 posts, 0 answers
  1. Holly
    Holly avatar
    11 posts
    Member since:
    Jul 2015

    Posted 26 Aug 2015 Link to this post

    Hi I am trying to add add a RadComboxBox to my RadGrid filtertemplate in a bound column.  For some reason in the code behind I can not access the RadComboBox.  It keeps coming back null.  I'm not sure what I'm doing wrong.  Here is my code.

    <telerik:GridBoundColumn SortExpression="Product_Name" HeaderText="Product Name" DataField="Product_Name" UniqueName="ProductName">
                                 <FilterTemplate>                                 
                                    <telerik:RadComboBox runat="server" ID="cmbProductName" CheckBoxes="true" ClientIDMode="Static" 
                                         AppendDataBoundItems="true" DataValueField="Product_Name" EnableCheckAllItemsCheckBox="true">                                
                                    </telerik:RadComboBox>
                                </FilterTemplate>
                            </telerik:GridBoundColumn>

     

     foreach (var cat in CatProdList)
                {               
                    var itemCategory = new RadComboBoxItem(cat.Category.Name);

                    var option = cat.ProdAttributesTuple.GroupBy(a => a.Item2.Attribute.Value).ToList();
                    foreach (var attr in option)
                    {
                        if (e.Item is GridDataItem)
                        { 
                            RadComboBox cmbProductName = (RadComboBox)e.Item.FindControl("cmbProductName");                      

                            var item = new RadComboBoxItem(attr.Key);

                            cmbProductName.Items.Add(item);                    
                        
                        }
                            
                    }
                }     

  2. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 31 Aug 2015 Link to this post

    Hi Holly,

    The combo is not located in a GridDataItem, but within a GridFilteringItem. You can get a reference to the GridFilteringItem during ItemDataBound event handler of the grid using the if(e.Item is GridFilteringItem) or during PreRender:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/using-the--getitems-getcolumn-and-getcolumnsafe-methods

    Generally, you can check the following live sample for implementing filtering with combo:
    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

    I suggest that you also check the samples provided in the following post:
    http://www.telerik.com/forums/how-to-persist-dropdownlist-selected-index-and-value-on-postback-from-radgrid-filtertemplate#GW3MyQLmVEmy8XzsmrHzeQ         


    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
  4. Holly
    Holly avatar
    11 posts
    Member since:
    Jul 2015

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

    Ok.  This is what I have now and it is still not working.

    <telerik:GridBoundColumn SortExpression="Product_Name" HeaderText="Product Name" DataField="Product_Name" UniqueName="ProductName" AllowFiltering="true">
                                        <FilterTemplate>
                                            <telerik:RadComboBox runat="server" ID="cmbProductName"></telerik:RadComboBox>
                                        </FilterTemplate>                                         
                            </telerik:GridBoundColumn>

     

                foreach (var cat in CatProdList)
                {
                    //var itemCategory = new RadComboBoxItem(cat.Category.Name);

                    var option = cat.ProdAttributesTuple.GroupBy(a => a.Item2.Attribute.Value).ToList();
                    foreach (var attr in option)
                    {
                        foreach (GridFilteringItem filterItem in RadGridDiscounts.MasterTableView.GetItems(GridItemType.FilteringItem))
                        {
                            //RadComboBox cmbProductName = (e.Item as GridFilteringItem).FindControl("cmbProductName") as RadComboBox;
                            var cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
                            var item = new RadComboBoxItem(attr.Key);


                            if (cmbProductName != null)
                            {
                                cmbProductName.Items.Add(item);
                            }
                        }
                    }
                }

     

    ​The data is coming back fine, but cmbProductName is still coming back as null.  What am I doing wrong?  Thank you.

  5. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 03 Sep 2015 Link to this post

    Hi Holly,

    I've created a sample RadGrid web site to test the described behavior. Please run the attached application and let me know about the result.

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