hi all
does any know how to convert this one

switch (((Filter)c).FilterModifier)

im getting error -
Cannot convert type 'System.Web.UI.Control' to 'Reports.Filter'
Filter is a class containing a collection od filters.
Reports is a class of the reports and the filter collection is linked with the reports.
c is a control and i want to get .FilterModifier in the Filter class for control c

9 Years
Discussion Span
Last Post by tucko

Can you post more of the code? I've never seen a Control with that property that's part of System.Web.UI.Control.

On top of that, even if that particular cast is possible, that looks a bit confusing. Why not do this:

Control c; 
Filter myFilter = (Filter)c; //that's assuming this is possible


	//rest of your code

again, assuming that's even possible.

Another thing to consider is that the switch statement only works with primitive types. Is FilterModifier an enum or something?


ok here is what i need.

i have several custom web controls.
filter is a class where filters for 'class reports' are stored.

public class Filter : DBmethods
        #region Private Variables
        private int _Sifra;
        private int _Reports_ID;
        private string _FilterName;
        private string _FilterDataType;
        private string _FilterModifier;
        private bool _FilterHasHierarchy;
        private bool _FilterHasSpisok;
        private bool _FilterMandatory;
        private int _FilterOrder;

i set the filters as collection and load them in class report.

than i create the web controls

foreach (Filter F in _R.Filters)
            Control C = null;
            switch (F.FilterModifier)
                case "TEXT":
                    C = new LbControls.TextField();
                case "NUMERIC":
                    C = new LbControls.NumericField();
                case "DATE":
                    C = new LbControls.DateField();
                case "COMBO":
                    C = new LbControls.VnosSifraNaziv();
                    if (F.FilterHasHierarchy == true)
                        //C.ShowHierarhija = true;

                    F.Conn = _R.Conn;
                case "CHECKBOX":
                    C = new LbControls.BooleanField();

im using component one and I add the controls in 'spliter'


now controls are all set and i need to fill them with data

private void FillControls()
        foreach (Control c in Web_FilterSpliter_Panel1.Controls)


and SetControl(c) is

private void SetControl(Control c)
            switch (((Filter)c).FilterModifier)// im trying to cast control as filter
                case "TEXT":

i need to get the filterModifier for the control c and than to bind the webcontrol with data acording to that filter modifier.
filtermodifier has data about the type of the control ex 'TEXT','COMBO' etc
i can render the controls properly but i can't bind them with data. That data is the text of the 'LABEL' or the items in the 'COMBO'

Edited by diafol: fixed formatting


I think it still boils down to the fact that you can't cast a Control to that Filter type directly. You're going to have to write logic to do that conversion, or something.


Can you please give me some knowledge how to do that. Im switching from VB.NET to C# and i've tried this code in vb, cType solves the problem. Please paste some example code!
Thanks for replying my post!

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.