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

Accessing RadComboBox Inside RadGrid FilterTemplate

3 Answers 367 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Holly
Top achievements
Rank 1
Holly asked on 26 Aug 2015, 01:21 PM

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);                    
                    
                    }
                        
                }
            }     

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 31 Aug 2015, 10:26 AM
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
0
Holly
Top achievements
Rank 1
answered on 31 Aug 2015, 03:09 PM

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.

0
Eyup
Telerik team
answered on 03 Sep 2015, 10:30 AM
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
Tags
ComboBox
Asked by
Holly
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Holly
Top achievements
Rank 1
Share this question
or