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);
}
}
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);
}
}
}
}
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);
}
}
}
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.
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.
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.
Member
174 Points
700 Posts
Find RadComboBox Inside RadGrid
Aug 26, 2015 10:11 AM|hollyquinn|LINK
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.
Batman Comics
All-Star
50841 Points
9895 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 01:35 PM|A2H|LINK
You need to loop through each column in MasterTableView of RadGrid prior to accessing the combobox
Aje
My Blog | Dotnet Funda
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 01:48 PM|hollyquinn|LINK
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?
Batman Comics
All-Star
50841 Points
9895 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 02:00 PM|A2H|LINK
Try debugging your code and check if the items is having a proper RadComboBox item assigned to it.
Aje
My Blog | Dotnet Funda
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 02:11 PM|hollyquinn|LINK
I'm sorry how do I do this? What am I looking for when I debug?
Batman Comics
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 02:13 PM|hollyquinn|LINK
When I hover over item it says item = {Telerik.Web.UI.RadComboBoxItem}. Is that what I"m looking for?
Batman Comics
All-Star
50841 Points
9895 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 02:50 PM|A2H|LINK
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
C#:
Aje
My Blog | Dotnet Funda
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 03:40 PM|hollyquinn|LINK
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.
This is in the RadGridDiscounts_ItemDataBound method:
Batman Comics
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 03:41 PM|hollyquinn|LINK
Could this have anything to do with my RadGrid being inside of a UserControl?
Batman Comics
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 26, 2015 03:53 PM|hollyquinn|LINK
I tried this in the pageload
Even with the dummy data it's not adding anything to my RadComboBox. Am I maybe not finding the control correctly?
Batman Comics
All-Star
50841 Points
9895 Posts
Re: Find RadComboBox Inside RadGrid
Aug 27, 2015 08:38 AM|A2H|LINK
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
Aje
My Blog | Dotnet Funda
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 27, 2015 01:14 PM|hollyquinn|LINK
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.
Batman Comics
Member
174 Points
700 Posts
Re: Find RadComboBox Inside RadGrid
Aug 27, 2015 04:38 PM|hollyquinn|LINK
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:
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.
Batman Comics