locked
Find RadComboBox Inside RadGrid RRS feed

  • Question

  • User-971051533 posted

    Hi.  I am trying to add a RadComboBox inside of a RadGrid filter template.  For some reason, I can't access the RadComboBox from the code behind.  I'm doing it exactly like they show to do it on the telerik site, and the RadComboBox keeps coming back as null.  Here is a portion of my code.  If anyone can tell me what I'm doing wrong that would be great.

     <telerik:GridBoundColumn SortExpression="Product_Name" HeaderText="Product Name" DataField="Product_Name" UniqueName="ProductName" AllowFiltering="true">
                                 <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)
                    {
                        foreach (GridFilteringItem filterItem in RadGridDiscounts.MasterTableView.GetItems(GridItemType.FilteringItem))
                        {
                            RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
    
                            var item = new RadComboBoxItem(attr.Key);
    
                           cmbProductName.Items.Add(item);                    
                        
                        }
                            
                    }

    Wednesday, August 26, 2015 10:11 AM

Answers

  • User2103319870 posted

    Unfortunately I am not finding the reason why you are not able to find the control properly. You might consider your question in Telerik Forum also

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2015 8:38 AM

All replies

  • User2103319870 posted

    I can't access the RadComboBox from the code behind.  I'm doing it exactly like they show to do it on the telerik site, and the RadComboBox keeps coming back as null.

    You need to loop through each column in MasterTableView of RadGrid prior to accessing the combobox

     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)
                        {
                            //Looping through each items in Mastertableview
                            foreach (GridFilteringItem filterItem in RadGridDiscounts.MasterTableView.GetItems(GridItemType.FilteringItem))
                            {
                                //Loop through each column in Mastertableview
                                foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
                                {
                                    RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
                                    var item = new RadComboBoxItem(attr.Key);
                                    cmbProductName.Items.Add(item);
                                }
                            }
                        }
                    }

    Wednesday, August 26, 2015 1:35 PM
  • User-971051533 posted

    Hi a2h,

    I tried this.  On the line cmbProductName.Items.Add(item); I'm getting the error message:

    An exception of type 'System.NullReferenceException' occurred in App_Web_wzodq52c.dll but was not handled in user code

    Additional information: Object reference not set to an instance of an object.

    I'm getting a value for item.  I'm not sure what is wrong?

    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))
                        {
                            //Loop through each column in Mastertableview
                            foreach (GridColumn column in RadGridDiscounts.MasterTableView.Columns)
                            {
                                RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
                                var item = new RadComboBoxItem(attr.Key);
                                cmbProductName.Items.Add(item);
                            }
                        }
    
                    }

    Wednesday, August 26, 2015 1:48 PM
  • User2103319870 posted

    I tried this.  On the line cmbProductName.Items.Add(item); I'm getting the error message:

    Try debugging your code and check if the items is having a proper RadComboBox item assigned to it.

    Wednesday, August 26, 2015 2:00 PM
  • User-971051533 posted

    Try debugging your code and check if the items is having a proper RadComboBox item assigned to it.

    I'm sorry how do I do this?  What am I looking for when I debug?

    Wednesday, August 26, 2015 2:11 PM
  • User-971051533 posted

    When I hover over item it says item = {Telerik.Web.UI.RadComboBoxItem}.  Is that what I"m looking for?

    Wednesday, August 26, 2015 2:13 PM
  • User2103319870 posted

    I am not sure why you are getting the exception. Please find the complete code which I tried and it working fine in my sample application

    HTML

     <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Width="300px"
            AllowFilteringByColumn="true">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="order_status" HeaderText="order_status"
                        DataField="order_status" UniqueName="ProductName" AllowFiltering="true">
                        <FilterTemplate>
                            <telerik:RadComboBox runat="server" ID="cmbProductName" CheckBoxes="true" ClientIDMode="Static"
                                AppendDataBoundItems="true" DataValueField="order_status" EnableCheckAllItemsCheckBox="true">
                            </telerik:RadComboBox>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

    C#:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsPostBack)
                {
    
                    DataTable table = new DataTable();
                    table.Columns.Add("order_status", typeof(string));
                    // Add Three rows with those columns filled in the DataTable.
                    table.Rows.Add("0");
                    table.Rows.Add("1");
                    table.Rows.Add("2");
                    table.Rows.Add("3");
                    table.Rows.Add("1");
                    table.Rows.Add("2");
                    table.Rows.Add("3");
    
                    RadGrid1.DataSource = table;
                    RadGrid1.DataBind();
    
                    //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 RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
                    {
                        foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
                        {
                            RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
                            var item = new RadComboBoxItem("text");
    
                            cmbProductName.Items.Add(item);
                        }
                    }
                }
            }
    

    Wednesday, August 26, 2015 2:50 PM
  • User-971051533 posted

    I tried doing it the way you did with some dummy text.  It still comes back with the null reference error.  Can you look at all of my code and let me know if you see any issues?  I'll post my grid below, and then my code behind below that.  If you don't see any problems.  I'll leave you alone.  Thanks for your help.

    <telerik:RadGrid ID="RadGridDiscounts" runat="server" ShowStatusBar="true" AutoGenerateColumns="false" 
            AllowMultiRowSelection="false" AllowFilteringByColumn="true" 
            OnNeedDataSource="RadGridDiscounts_NeedDataSource" OnPreRender="RadGridDiscounts_PreRender"
            OnItemDataBound="RadGridDiscounts_ItemDataBound" Skin="Web20" ClientSettings-AllowExpandCollapse="true">
            <PagerStyle Mode="NumericPages" />
    
            <MasterTableView DataKeyNames="Category_ID" AllowMultiColumnSorting="true" HierarchyLoadMode="Client" DataMember="Categories">
    
                <DetailTables>
    
                    <telerik:GridTableView DataKeyNames="Product_ID" Name="Products" HierarchyLoadMode="Client" DataMember="Products">
                        <ColumnGroups>
                            <telerik:GridColumnGroup HeaderText="Parent" Name="Parent" HeaderStyle-HorizontalAlign="Center"></telerik:GridColumnGroup>
                            <telerik:GridColumnGroup HeaderText="Account" Name="Discount" HeaderStyle-HorizontalAlign="Center"></telerik:GridColumnGroup>
                            <telerik:GridColumnGroup HeaderText="Margin" Name="Margin" HeaderStyle-HorizontalAlign="Center"></telerik:GridColumnGroup>
                        </ColumnGroups>
    
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="Category_ID" MasterKeyField="Category_ID" />
                        </ParentTableRelation>
    
                        <%--Detail Table For Second Spiff--%>
                        <DetailTables>
                            <telerik:GridTableView HierarchyLoadMode="Client" Name="SecondSpiffs" DataMember="SecondSpiffs" runat="server" >
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="SpiffProductID" MasterKeyField="Product_ID"></telerik:GridRelationFields>
                                </ParentTableRelation>
                                <Columns>
                                    <telerik:GridBoundColumn UniqueName="SpiffSplitProductID" HeaderText="Spiff Product ID" DataField="SpiffSplitProductID"></telerik:GridBoundColumn>
                                    
                                    <telerik:GridBoundColumn HeaderText="Spiff Product Name" DataField="SpiffProductName" UniqueName="Attribute">                                   
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn HeaderText="Lock Discount" UniqueName="LockDiscount" AllowFiltering="false">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkLockDiscount" runat="server" Checked='<%# Eval("Lock_Discount") %>'/>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Approved To Sell" AllowFiltering="false">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkStatus" runat="server" Checked='<%# Eval("ApprovedToSell_Flg") %>'/>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Parent Spiff" AllowFiltering="false">
                                        <ItemTemplate>
                                            <asp:Label ID="ParentSpiff" runat="server" Text='<%# Eval("ParentSpiffAmount") %>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Discount" AllowFiltering="false">
                                        <ItemTemplate>
                                            <asp:TextBox ID="ChildSpiff" runat="server" Columns="7" Text='<%# Eval("ChildSpiffAmount") %>' ></asp:TextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn Display="false">
                                        <ItemTemplate>
                                            <asp:Label id="SpiffOrder" runat="server" Text='<%# Eval("Order") %>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn UniqueName="SpiffSplitMappingID" Display="false" DataField="SpiffSplitMappingID" />
                                    <telerik:GridBoundColumn UniqueName="SpiffProductID" Display="false" DataField="SpiffProductID" />
                                    <telerik:GridBoundColumn UniqueName="SpiffSplitID" Display="false" DataField="SpiffSplitID" />
                                    <telerik:GridCheckBoxColumn DataField="Lock_Discount" UniqueName="hfDiscountLock" Display="false" />
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
    
                        <Columns>
    
                            <telerik:GridBoundColumn SortExpression="Product_ID" HeaderText="Product ID" DataField="Product_ID" AllowFiltering="true" />
                            
                            <telerik:GridBoundColumn SortExpression="Product_Name" HeaderText="Product Name" DataField="Product_Name" UniqueName="ProductName" AllowFiltering="true">
                                 <FilterTemplate>         
                                    <telerik:RadComboBox runat="server" ClientIDMode="Static" DataValueField="Product_Name" ID="cmbProductName" CheckBoxes="true" AppendDataBoundItems="true" EnableCheckAllItemsCheckBox="true">  
                                        <Items>
                                            
                                        </Items>                              
                                    </telerik:RadComboBox>
                                    <asp:DropDownList runat="server" ID="ddl"></asp:DropDownList>
                                </FilterTemplate>
                            </telerik:GridBoundColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Approved To Sell" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkApprovedToSell" runat="server" Checked='<%# CheckApprovedToSellFlag(Container.DataItem) %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Lock Discount" UniqueName="LockDiscount" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkLockDiscount" runat="server" Checked='<%# Eval("Lock_Discount") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Discount" ColumnGroupName="Parent" ItemStyle-Width="120px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:Label ID="txtParentDiscount" runat="server" Text='<%# DiscountFormat(Container.DataItem, "parent") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Price" ColumnGroupName="Parent" ItemStyle-Width="120px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:Label ID="txtParentPrice" runat="server" Text='<%# FinalPriceFormat(Container.DataItem, "parent") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Discount" ColumnGroupName="Discount" ItemStyle-Width="120px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtAccountDiscount" runat="server" Text='<%# DiscountFormat(Container.DataItem, "account") %>' Width="80%"></asp:TextBox>
                                    <asp:Label ID="lblNewProduct" runat="server" Font-Bold="true" ForeColor="Red"  Font-Size="Large"></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Price" ColumnGroupName="Discount" ItemStyle-Width="120px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtAccountPrice" runat="server" Text='<%# FinalPriceFormat(Container.DataItem, "account") %>' Width="80%" Enabled="<%# PriceEnable(Container.DataItem) %>"></asp:TextBox>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Discount" UniqueName="Margin" ColumnGroupName="Margin" ItemStyle-Width="120px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:Label ID="txtMargin" runat="server" Text='<%# DiscountFormat(Container.DataItem, "margin") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Amount" ColumnGroupName="Margin" ItemStyle-Width="120px" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:Label ID="txtMarginPrice" runat="server" Text='<%# FinalPriceFormat(Container.DataItem, "margin") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                            <telerik:GridTemplateColumn HeaderText="Discount Type" AllowFiltering="false">
                                <ItemTemplate>                                                
                                    <asp:RadioButton ID="rbDollar"  runat="server" Text="$" GroupName="DiscountType" AutoPostBack="false" Checked='<%#CheckDollarDiscountType(Container.DataItem)%>' Enabled="false"/>                                      
                                    <asp:RadioButton ID="rbPercent" runat="server" Text="%" GroupName="DiscountType" AutoPostBack="false" Checked='<%#CheckPercentDiscountType(Container.DataItem)%>' Enabled="false"/>                                             
                                    <asp:HiddenField ID="hfProductID" runat="server" Value='<%# Eval("Product_ID") %>' />
                                    <asp:HiddenField ID="hfDiscountLock" runat="server" Value='<%# Eval("Lock_Discount") %>' />
                                    <asp:HiddenField ID="hfBasePrice" runat="server" Value='<%# Eval("Base_Price") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
    
                        </Columns>
    
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="Parent_ID" HeaderText="Parent_ID" DataField="Parent_ID" Visible="false"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="Category_Name" HeaderText="Category" HeaderButtonType="TextButton" DataField="Category_Name" Visible="false"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="Carrier_Name" HeaderText="Product Category" HeaderButtonType="TextButton" DataField="Carrier_Name" AllowFiltering="false"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Parent Discount" Visible="true" AllowFiltering="false">
                        <ItemTemplate>
                            <asp:label ID="lblCarrierParentAccountDiscount" runat="server" Text="" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Apply Approved To Sell To All" Visible="true" AllowFiltering="false">
                        <ItemTemplate>
                            <asp:CheckBox ID="chkCarrierApprovedToSell" runat="server" Text="" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Discount" Visible="true" AllowFiltering="false">
                        <ItemTemplate>
                            <asp:TextBox ID="txtCarrierAccountDiscount" runat="server"></asp:TextBox>
                            <asp:Label ID="txtCarrierNewProduct" runat="server" BorderStyle="None" Font-Bold="true" ForeColor="Red"  Font-Size="Large"></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView> 
            <ClientSettings></ClientSettings>     
        </telerik:RadGrid>

    This is in the RadGridDiscounts_ItemDataBound method:

    List<int> productIds = new List<int>();
                DataRow[] productRow = CategoriesProductsData.Tables["Products"].Select("Category_ID = " + 573);
    
                productIds = productRow.Select(p => int.Parse(p["Product_ID"].ToString())).ToList();
    
                ITCProductService pService = new TCProductServiceClient();
                var productTuples = (pService.GetProductsAttributes(productIds));
    
                List<Tuple<int, CustomAttribute>> customAttributes = new List<Tuple<int, CustomAttribute>>();
                foreach (var productTuple in productTuples)
                {                
                    foreach (var attributeTuple in productTuple.m_Item2)
                    {
                        var customAttribute = new Tuple<int, CustomAttribute>(productTuple.m_Item1, new CustomAttribute(attributeTuple));
                        customAttributes.Add(customAttribute);
                    }
    
                }
    
                List<CustomAttributeCategory> categories = new List<CustomAttributeCategory>();
    
                var categoryList = customAttributes.Select(a => a.Item2).Select(a => a.Attribute.Category).GroupBy(a => a.AttributeCategoryId);
    
                var CatProdList = new List<CustomAttributeCategory>();
    
                foreach (var category in categoryList)
                {
                    var CatProd = new CustomAttributeCategory();
    
                    var prodIDList = from product in customAttributes
                                     where product.Item2.Attribute.CategoryId == category.Key
                                     select Tuple.Create(product.Item1, product.Item2);
    
                    CatProd.Category = customAttributes.Select(a => a.Item2.Attribute.Category).Where(a => a.AttributeCategoryId == category.Key).FirstOrDefault();
                    CatProd.ProdAttributesTuple = new List<Tuple<int, CustomAttribute>>();
                    CatProd.ProdAttributesTuple = prodIDList.ToList();
    
                    CatProdList.Add(CatProd);
                }
    
                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))
                            {
                                foreach (GridColumn column in RadGridDiscounts.MasterTableView.Columns)
                                {  
                                   RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
                                   var item = new RadComboBoxItem(attr.Key);
                                   item.Text = attr.Key.ToString();
                                   item.Value = attr.Key;  
    
                                   if (cmbProductName == null)
                                   {
                                       
                                   } 
                                   else
                                   {
                                       cmbProductName.Items.Add(item);
                                   }
                                   
                                }
    
                            }  
                    }
                }  

    public class CustomAttributeCategory
        {
            public AttributeCategoryModel Category { get; set; }
            public List<Tuple<int, CustomAttribute>> ProdAttributesTuple { get; set; }
        }
    
        public class CustomAttribute
        {
            public AttributeModel Attribute { get; set; }
    
            public List<int> ProductIds { get; set; }
    
            public CustomAttribute(AttributeModel attribute)
            {
                Attribute = attribute;
                ProductIds = new List<int>();
            }
        }
    
    

    Wednesday, August 26, 2015 3:40 PM
  • User-971051533 posted

    Could this have anything to do with my RadGrid being inside of a UserControl?

    Wednesday, August 26, 2015 3:41 PM
  • User-971051533 posted

    I tried this in the pageload

    foreach (GridFilteringItem filterItem in RadGridDiscounts.MasterTableView.GetItems(GridItemType.FilteringItem))
            {
                foreach (GridColumn column in RadGridDiscounts.MasterTableView.Columns)
                {
                    RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
                    var item = new RadComboBoxItem("text");
                    cmbProductName.Items.Add(item);
                }
            }
    <telerik:GridBoundColumn SortExpression="Product_Name" HeaderText="Product Name" DataField="Product_Name" UniqueName="ProductName" AllowFiltering="true">
                                 <FilterTemplate>         
                                    <telerik:RadComboBox runat="server" ClientIDMode="Static" DataValueField="Product_Name" ID="cmbProductName" CheckBoxes="true" AppendDataBoundItems="true" EnableCheckAllItemsCheckBox="true">  
                                        <Items>
                                            
                                        </Items>                              
                                    </telerik:RadComboBox>                               
                                </FilterTemplate>
                            </telerik:GridBoundColumn>


    Even with the dummy data it's not adding anything to my RadComboBox.  Am I maybe not finding the control correctly?

    Wednesday, August 26, 2015 3:53 PM
  • User2103319870 posted

    Unfortunately I am not finding the reason why you are not able to find the control properly. You might consider your question in Telerik Forum also

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2015 8:38 AM
  • User-971051533 posted

    I posted in Telerik 2 days ago and haven't heard back yet.  I don't find anything wrong with the code either.  I think there might be something wrong with the Grid itself.  Thanks for your help.

    Thursday, August 27, 2015 1:14 PM
  • User-971051533 posted

    Hi a2h,

    I know I marked this as answered, but I was wondering if you could help me with one last thing with it.  I found out that the RadGrid, which is inside of a usercontrol is created inside of a aspx page when a RadPanel is clicked.  I figured that I needed to add the RadComboBox items at this point in my  application.  This is what I've got:

    foreach (GridFilteringItem filterItem in ((RadGrid)userControl.FindControl("RadGridDiscounts")).MasterTableView.GetItems(GridItemType.FilteringItem))
                        {
                            foreach (GridColumn column in ((RadGrid)userControl.FindControl("RadGridDiscounts")).MasterTableView.Columns)
                            {                          
                             
                                RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName");
    
                                var item1 = new RadComboBoxItem(attr.Key);
                                item1.Text = attr.Key.ToString();
                                item1.Value = attr.Key;
    
    
                                if (cmbProductName == null)
                                {
    
                                }
                                else
                                {
                                    cmbProductName.Items.Add(item1);
                                }
    
                            }
    
                        }
                    }

    It's working, except that I'm unsure how to find the RadComboBox inside the template filter.

    RadComboBox cmbProductName = (RadComboBox)filterItem.FindControl("cmbProductName"); doesn't work.  How can I code it to find it inside of the usercontrol?  If you can help me that'd be great, but if not don't worry about it.  Just thought I'd give it a try.  Thanks.

    Thursday, August 27, 2015 4:38 PM