Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'Telerik.WebControls.RadComboBox'.
the same thing working fine with parent grid but failing in Detail Grid.
Can anyone help me to resolve this issue.
3 Answers, 1 is accepted

I am not quite sure where you are getting this error. This error will occur if you are trying to cast a control of type TextBox into RadComboBox. If you are trying any code in ItemDataBound event, check whether you have differentiated the item in MasterTable and Detail table. The following documentation shows how to achieve this.
Distinguish grid rows in hierarchy on ItemCreated/ItemDataBound
And make sure you have accessed all the control in correct format. Please paste your code if it doesn't help.
Thanks,
Princy.

Here is the code i am using to apply custom filters , i am getting the error in the Yellow Highlighted code , for some reason its not reading the custome filter i.e DropDown control , its reading as TextBox which is the default Filter control.
public class CustomFiltersCheckBoxForTemplate : GridTemplateColumn
{
private object listDataSource = null;
//RadGrid will call this method when it initializes the controls inside the filtering item cells
protected override void SetupFilterControls(TableCell cell)
{
base.SetupFilterControls(cell);
cell.Controls.RemoveAt(0);
System.Web.UI.WebControls.DropDownList list = new System.Web.UI.WebControls.DropDownList();
list.ID = "list" + this.DataField;
//list.Height = Unit.Pixel(300);
list.AutoPostBack = true;
list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
cell.Controls.AddAt(0, list);
cell.Controls.RemoveAt(1);
list.DataSource = this.ListDataSource;
list.DataTextField = this.DataText;//this.DataField;
list.DataValueField = this.DataValue; //this.DataField;
list.DataBind();
}
void list_SelectedIndexChanged(object sender, EventArgs e)
{
GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;
this.SelectedValue = (sender as DropDownList).SelectedValue;
this.FilteredColumnName = this.UniqueName;
//if (this.UniqueName == "Index")
//{
// //this is example for filtering for integer column type
// filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
//}
////filtering for string column type
//filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));
filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
}
public object ListDataSource
{
get
{
return this.listDataSource;
}
set
{
listDataSource = value;
}
}
public string SelectedValue
{
get
{
object res = this.Owner.OwnerGrid.Page.Session["SelectedValue"];
if (res != null)
{
return (string)res;
}
return "";
}
set
{
this.Owner.OwnerGrid.Page.Session["SelectedValue"] = value;
}
}
public string FilteredColumnName
{
get
{
object res = this.Owner.OwnerGrid.Page.Session["FilteredColumnName"];
if (res != null)
{
return (string)res;
}
return "";
}
set
{
this.Owner.OwnerGrid.Page.Session["FilteredColumnName"] = value;
}
}
//RadGrid will call this method when the value should be set to the filtering input control(s)
protected override void SetCurrentFilterValueToControl(TableCell cell)
{
base.SetCurrentFilterValueToControl(cell);
System.Web.UI.WebControls.DropDownList list = (System.Web.UI.WebControls.DropDownList)cell.Controls[0];
if (this.CurrentFilterValue != string.Empty)
{
list.SelectedValue = this.CurrentFilterValue;
}
}
//RadGrid will call this method when the filtering value should be extracted from the filtering input control(s)
protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
System.Web.UI.WebControls.DropDownList list = (System.Web.UI.WebControls.DropDownList)cell.Controls[0];
return list.SelectedValue;
return this.SelectedValue;
}
public override GridColumn Clone()
{
CustomFiltersCheckBoxForTemplate res = new CustomFiltersCheckBoxForTemplate();
res.CopyBaseProperties(this);
return res;
}
protected override void CopyBaseProperties(GridColumn fromColumn)
{
base.CopyBaseProperties(fromColumn);
CustomFiltersCheckBoxForTemplate inColumn = fromColumn as CustomFiltersCheckBoxForTemplate;
this.DataField = inColumn.DataField;
this.DataValue = inColumn.DataValue;
this.DataText = inColumn.DataText;
}
protected override string GetFilterDataField()
{
return this.DataField;
}
public virtual string DataText { get; set; }
public virtual string DataValue { get; set; }
}
I reviewed the source code which you post and it looks correct, however it is not runnable and I could not reproduce the described issue. Could you please send us a simple runnable example which demonstrates the described error. You could open a formal support ticket from your Telerik account and attach a ZIP file there. Thus we will be able to gather more details about your scenario and to provide you a solution.
Best wishes,
Radoslav
the Telerik team