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

Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'Telerik.WebControls.RadComboBox'.

3 Answers 2208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
v s
Top achievements
Rank 1
v s asked on 07 Dec 2010, 09:54 PM
I am using Custom Dropdown Filter for a template comun in detail grid , the dropdown is coming fine but when i selected value to filter i am getting the below error
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

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Dec 2010, 07:43 AM
Hello,

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.
0
v s
Top achievements
Rank 1
answered on 08 Dec 2010, 10:45 PM

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

    }

 

 

0
Radoslav
Telerik team
answered on 13 Dec 2010, 02:40 PM
Hi v s,

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
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
v s
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
v s
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or