New to c# question

Hello,

i have soem code that i am trying to build in my c# app that would allow me to build some controls dynamicly. i have fixed most fo the errors but my parent/placeholder controls are giving me errors. anything with Placeholder.controls.add gives me errors

ERROR
'object' does not contain a definition for 'Controls' and no extension method 'Controls' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace Synamics
{
    public class Dynamic
    {
        public void WebButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            Button b = new Button();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;
            b.Text = ButtonText;
            b.EnableViewState = true;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            ParentControl.Controls.Add(b);
        }
        public void WebLinkButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            LinkButton b = new LinkButton();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;

            //     b.ForeColor = Drawing.Color.WhiteSmoke
            b.Text = ButtonText;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            ParentControl.Controls.Add(b);
        }
        public void WebLinkButtonNewBlue(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            LinkButton b = new LinkButton();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;
            b.ForeColor = System.Drawing.Color.Blue;
            //     b.ForeColor = Drawing.Color.WhiteSmoke
            b.Text = ButtonText;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            ParentControl.Controls.Add(b);
        }
        public void WebCellLinkButtonBlue(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler, string AlignOption = "", int ColSpan = 0)
        {
            LinkButton b = new LinkButton();
            TableCell tc = new TableCell();

            // *****
            // ***** Give table cell the optional values
            // *****
            if (AlignOption == "C")
            {
                tc.HorizontalAlign = HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            WebLinkButtonNewBlue(tc, ButtonID, ButtonText, Handler);
            // *****
            // ***** Add the cell to the ParentControl
            // *****
            ParentControl.Controls.Add(tc);
        }
        public void WebCellLinkButtonNe(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler, string AlignOption = "", int ColSpan = 0)
        {
            LinkButton b = new LinkButton();
            TableCell tc = new TableCell();

            // *****
            // ***** Give table cell the optional values
            // *****
            if (AlignOption == "C")
            {
                tc.HorizontalAlign =  HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            WebLinkButtonNew(tc, ButtonID, ButtonText, Handler);
            // *****
            // ***** Add the cell to the ParentControl
            // *****
            ParentControl.Controls.Add(tc);
        }
        public void WebCellButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler, string AlignOption = "", int ColSpan = 0)
        {
            Button b = new Button();
            TableCell tc = new TableCell();

            // *****
            // ***** Give table cell the optional values
            // *****
            if (AlignOption == "C")
            {
                tc.HorizontalAlign = HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            WebButtonNew(tc, ButtonID, ButtonText, Handler);
            // *****
            // ***** Add the cell to the ParentControl
            // *****
            ParentControl.Controls.Add(tc);
        }

        public void WebCellCheckBoxNew(object Parent, string ID, string EN, bool Value)
        {
            TableCell c = new TableCell();
            c.Width = 1;
            WebCheckBoxNew(c, ID, Value, EN);
            Parent.controls.@add(c);
        }
        public void WebCellRadioNew(object Parent, string ID, string GN, string EN, string TX, bool Value)
        {
            TableCell c = new TableCell();
            c.Width = 1;
            WebRadioNew(c, ID, GN, EN, TX, Value);
            Parent.controls.@add(c);
        }
        public void WebRadioNew(object Parent, string ID, string GN, string EN, string TX, bool Value)
        {
            RadioButton rb = new RadioButton();
            rb.ID = ID;
            rb.Text = TX;
            rb.Visible = EN;
            rb.GroupName = GN;
            rb.Checked = Value;
            Parent.controls.@add(rb);
        }


        public void WebCellHyperLinkNew(object Parent, string ID, bool Value)
        {
            HyperLink c = new HyperLink();
            c.Width = 1;
            WebHyperLinkNew(c, ID, Value);
            Parent.controls.@add(c);
        }

        public void WebCellNew(ref TableRow TR, string CellText, string AlignOption = "L", int ColWidth = -1, int ColSpan = 1, bool AllowWrap = true)
        {
            TableCell tc = new TableCell();

            tc.Text = CellText;
            tc.Wrap = AllowWrap;
            if (AlignOption == "C")
            {
                tc.HorizontalAlign = HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColWidth != -1)
            {
                tc.Width = ColWidth;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            TR.Controls.Add(tc);
            tc = null;
        }

        public void WebCellTextBoxNew(object Parent, string ID, string TextBoxText, string cssclass = "", int cols = -1)
        {
            TableCell c = new TableCell();
            c.Width = 1;
            WebTextBoxNew(c, ID, TextBoxText, cssclass, cols);
            Parent.controls.@add(c);
        }

        public void WebCheckBoxNew(object Parent, string ID, string EN, bool Value)
        {
            CheckBox cb = new CheckBox();
            cb.ID = ID;
            cb.Visible = EN;
            cb.Checked = Value;
            Parent.controls.@add(cb);
        }

        public void WebHyperLinkNew(object Parent, string ID, bool Value)
        {
            HyperLink HP = new HyperLink();
            HP.ID = ID;
            Parent.controls.@add(HP);
        }

        public void WebHeaderCellNew(ref TableRow TR, string CellText, string AlignOption = "C", int ColumnWidth = 0, int ColumnSpan = 1, bool AllowWrap = true)
        {
            TableHeaderCell thc = new TableHeaderCell();

            if (ColumnSpan != 1)
            {
                thc.ColumnSpan = ColumnSpan;
            }
            thc.Wrap = AllowWrap;
            thc.Text = CellText;
            if (AlignOption == "L")
            {
                thc.HorizontalAlign = HorizontalAlign.Left;
            }
            else if (AlignOption == "R")
            {
                thc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColumnWidth != 0)
            {
                thc.Width = Unit.Percentage(ColumnWidth);
            }
            TR.Controls.Add(thc);
            thc = null;
        }

        public void WebLabelNew(object PH, string LabelText, string CSSClass = "")
        {
            Label l = new Label();

            l.Text = LabelText;
            l.CssClass = CSSClass;
            PH.Controls.Add(l);
            l = null;
        }

        public string WebTextBoxInput(PlaceHolder ph, string ControlName)
        {
            TextBox tb = default(TextBox);

            tb = ph.FindControl(ControlName);
            return tb.Text;
        }

        public void WebTextBoxNew(object PH, string ID, string TextBoxText, string CSSClass = "", int Cols = -1)
        {
            TextBox t = new TextBox();

            t.Text = TextBoxText;
            t.ID = ID;
            t.CssClass = CSSClass;
            if (Cols != -1)
            {
                t.Columns = Cols;
            }
            PH.Controls.Add(t);
            t = null;
        }

        public DropDownList WebCellDropDownList(ref object PH, string ID)
        {
            TableCell c = new TableCell();
            DropDownList ddl = default(DropDownList);

            c.Width = 1;
            ddl = WebDropDownList(ref c, ID);
            PH.controls.@add(c);
            return ddl;
        }

        public DropDownList WebDropDownList(ref object PH, string ID)
        {
            DropDownList ddl = new DropDownList();

            ddl.ID = ID;
            PH.controls.@add(ddl);
            return ddl;
        }

        public void WebDropDownListPopulate(ref DropDownList ddl, string[] values, int imax, string SelectedValue = "", string NoneSelectedValue = "")
        {
            int i = 0;

            if (!string.IsNullOrEmpty(NoneSelectedValue))
            {
                ddl.Items.Add(NoneSelectedValue);
            }
            for (i = 0; i <= imax; i++)
            {
                ddl.Items.Add(values[i]);
            }
            if (!string.IsNullOrEmpty(SelectedValue))
            {
                ddl.SelectedValue = SelectedValue;
            }
        }

        public DropDownList WebDropDownListInput(PlaceHolder ph, string ID)
        {
            DropDownList ddl = default(DropDownList);

            ddl = ph.FindControl(ID);
            return (ddl);
        }


    }
}

Open in new window

LVL 1
Chris JonesLead Application Web DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
because the parameter is of type object and not control/form or whatever type you are trying to add a control to. cast it to the correct type and then you should be fine.
0
käµfm³d 👽Commented:
*No points*

Side comment:  In terms of coding style, the recommended practice is to use "camel casing" for your local variables, including method parameters. So this:

public void WebButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)

Open in new window


...would become this:

public void WebButtonNew(object parentControl, string buttonID, string buttonText, System.EventHandler handler)

Open in new window


The reason for this is that it makes it clear whether or not a word is a class name or a variable. For example, if I gave you:

Button Button = new Button();

Button.DoSomething();

Open in new window


How would you know whether or not DoSomething was an instance method or a static method?
0
Chris JonesLead Application Web DeveloperAuthor Commented:
can you give me an exmpale of casting an object to for exmpale a dropdownlost
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

p_davisCommented:
//one way to do it
public void WebButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            Button b = new Button();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;
            b.Text = ButtonText;
            b.EnableViewState = true;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            (ParentControl as DropDownList).Controls.Add(b);
        }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris JonesLead Application Web DeveloperAuthor Commented:
oh i see so this woruld work


        public void WebLinkButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            LinkButton b = new LinkButton();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;

            //     b.ForeColor = Drawing.Color.WhiteSmoke
            b.Text = ButtonText;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            (ParentControl as LinkButton).Controls.Add(b);
        }

Open in new window

0
p_davisCommented:
it should...
0
Chris JonesLead Application Web DeveloperAuthor Commented:
so after i cast it i still get an errr when i try t oadd an item to the casted placeholder for exmpale

        public DropDownList WebDropDownListInput(PlaceHolder ph, string ID)
        {
            DropDownList ddl = default(DropDownList);

            ddl = ph.FindControl(ID);

            return (ddl);
        }

Open in new window




            ddl = ph.FindControl(ID); gives me an error

Error      20      'object' does not contain a definition for 'controls' and no extension method 'controls' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)      I:\Synamics\Synamics\Dynamic.cs      307      16      Synamics
0
käµfm³d 👽Commented:
It might not be of consequence in this particular example, but I would caution you to a feature of the as keyword:  It will attempt to cast the object to the target type, but if the object is not compatible with the target type--meaning that it is not somewhere in the inheritance chain of the target type--then as will return null. This would result in a NullReferenceException in the above example, if ParentControl were not actually a LinkButton.
0
p_davisCommented:
can you post the findcontrol() code?
0
p_davisCommented:
sorry -- i looked up the class to get it. so, nm
0
p_davisCommented:
that error doesn't seem to make any sense.. i don' see any variables in there that are of type object or where you are accessing anything referenced as controls
0
Chris JonesLead Application Web DeveloperAuthor Commented:
Hello,

these are the erorrs that i have after amking teh designaed changes

Error	2	The best overloaded method match for 'Synamics.Dynamic.WebCheckBoxNew(object, string, string, bool)' has some invalid arguments	I:\Synamics\Synamics\Dynamic.cs	151	13	Synamics
Error	3	Argument 3: cannot convert from 'bool' to 'string'	I:\Synamics\Synamics\Dynamic.cs	151	35	Synamics
Error	4	Argument 4: cannot convert from 'string' to 'bool'	I:\Synamics\Synamics\Dynamic.cs	151	42	Synamics
Error	5	Cannot implicitly convert type 'string' to 'bool'	I:\Synamics\Synamics\Dynamic.cs	166	26	Synamics
Error	6	Cannot implicitly convert type 'string' to 'bool'	I:\Synamics\Synamics\Dynamic.cs	219	26	Synamics
Error	7	Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'. An explicit conversion exists (are you missing a cast?)	I:\Synamics\Synamics\Dynamic.cs	272	18	Synamics
Error	8	The best overloaded method match for 'Synamics.Dynamic.WebDropDownList(ref object, string)' has some invalid arguments	I:\Synamics\Synamics\Dynamic.cs	297	19	Synamics
Error	9	Argument 1: cannot convert from 'ref System.Web.UI.WebControls.TableCell' to 'ref object'	I:\Synamics\Synamics\Dynamic.cs	297	39	Synamics
Error	10	Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.DropDownList'. An explicit conversion exists (are you missing a cast?)	I:\Synamics\Synamics\Dynamic.cs	333	19	Synamics

Open in new window



Here is my code after the changes you suggested

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Synamics
{
    public class Dynamic
    {
        public void WebButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            Button b = new Button();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;
            b.Text = ButtonText;
            b.EnableViewState = true;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            (ParentControl as Button).Controls.Add(b);
        }
        public void WebLinkButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            LinkButton b = new LinkButton();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;

            //     b.ForeColor = Drawing.Color.WhiteSmoke
            b.Text = ButtonText;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            (ParentControl as LinkButton).Controls.Add(b);
        }

        public void WebLinkButtonNewBlue(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler)
        {
            LinkButton b = new LinkButton();

            // *****
            // ***** Create the button
            // *****
            b.ID = ButtonID;
            b.ForeColor = System.Drawing.Color.Blue;
            //     b.ForeColor = Drawing.Color.WhiteSmoke
            b.Text = ButtonText;
            b.Click += Handler;
            // *****
            // ***** Add the button to the ParentControl
            // *****
            (ParentControl as LinkButton).Controls.Add(b);
        }
        public void WebCellLinkButtonBlue(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler, string AlignOption = "", int ColSpan = 0)
        {
            LinkButton b = new LinkButton();
            TableCell tc = new TableCell();

            // *****
            // ***** Give table cell the optional values
            // *****
            if (AlignOption == "C")
            {
                tc.HorizontalAlign = HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            WebLinkButtonNewBlue(tc, ButtonID, ButtonText, Handler);
            // *****
            // ***** Add the cell to the ParentControl
            // *****
            (ParentControl as TableCell).Controls.Add(tc);
        }
        public void WebCellLinkButtonNe(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler, string AlignOption = "", int ColSpan = 0)
        {
            LinkButton b = new LinkButton();
            TableCell tc = new TableCell();

            // *****
            // ***** Give table cell the optional values
            // *****
            if (AlignOption == "C")
            {
                tc.HorizontalAlign =  HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            WebLinkButtonNew(tc, ButtonID, ButtonText, Handler);
            // *****
            // ***** Add the cell to the ParentControl
            // *****
            (ParentControl as TableCell).Controls.Add(tc);
        }
        public void WebCellButtonNew(object ParentControl, string ButtonID, string ButtonText, System.EventHandler Handler, string AlignOption = "", int ColSpan = 0)
        {
            Button b = new Button();
            TableCell tc = new TableCell();

            // *****
            // ***** Give table cell the optional values
            // *****
            if (AlignOption == "C")
            {
                tc.HorizontalAlign = HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            WebButtonNew(tc, ButtonID, ButtonText, Handler);
            // *****
            // ***** Add the cell to the ParentControl
            // *****

            (ParentControl as TableCell).Controls.Add(tc);
        }

        public void WebCellCheckBoxNew(object Parent, string ID, string EN, bool Value)
        {
            TableCell c = new TableCell();
            c.Width = 1;
            WebCheckBoxNew(c, ID, Value, EN);
            (Parent as TableCell).Controls.Add(c);
        }
        public void WebCellRadioNew(object Parent, string ID, string GN, string EN, string TX, bool Value)
        {
            TableCell c = new TableCell();
            c.Width = 1;
            WebRadioNew(c, ID, GN, EN, TX, Value);
            (Parent as TableCell).Controls.Add(c);
        }
        public void WebRadioNew(object Parent, string ID, string GN, string EN, string TX, bool Value)
        {
            RadioButton rb = new RadioButton();
            rb.ID = ID;
            rb.Text = TX;
            rb.Visible = EN;
            rb.GroupName = GN;
            rb.Checked = Value;
            (Parent as RadioButton).Controls.Add(rb);
        }


        public void WebCellHyperLinkNew(object Parent, string ID, bool Value)
        {
            HyperLink c = new HyperLink();
            c.Width = 1;
            WebHyperLinkNew(c, ID, Value);
            (Parent as HyperLink).Controls.Add(c);
        }

        public void WebCellNew(ref TableRow TR, string CellText, string AlignOption = "L", int ColWidth = -1, int ColSpan = 1, bool AllowWrap = true)
        {
            TableCell tc = new TableCell();

            tc.Text = CellText;
            tc.Wrap = AllowWrap;
            if (AlignOption == "C")
            {
                tc.HorizontalAlign = HorizontalAlign.Center;
            }
            else if (AlignOption == "R")
            {
                tc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColWidth != -1)
            {
                tc.Width = ColWidth;
            }
            if (ColSpan != 1)
            {
                tc.ColumnSpan = ColSpan;
            }
            TR.Controls.Add(tc);
            tc = null;
        }

        public void WebCellTextBoxNew(object Parent, string ID, string TextBoxText, string cssclass = "", int cols = -1)
        {
            TableCell c = new TableCell();
            c.Width = 1;
            WebTextBoxNew(c, ID, TextBoxText, cssclass, cols);
            (Parent as TableCell).Controls.Add(c);
        }

        public void WebCheckBoxNew(object Parent, string ID, string EN, bool Value)
        {
            CheckBox cb = new CheckBox();
            cb.ID = ID;
            cb.Visible = EN;
            cb.Checked = Value;
            (Parent as CheckBox).Controls.Add(cb);
        }

        public void WebHyperLinkNew(object Parent, string ID, bool Value)
        {
            HyperLink HP = new HyperLink();
            HP.ID = ID;
            (Parent as TableCell).Controls.Add(HP);
        }

        public void WebHeaderCellNew(ref TableRow TR, string CellText, string AlignOption = "C", int ColumnWidth = 0, int ColumnSpan = 1, bool AllowWrap = true)
        {
            TableHeaderCell thc = new TableHeaderCell();

            if (ColumnSpan != 1)
            {
                thc.ColumnSpan = ColumnSpan;
            }
            thc.Wrap = AllowWrap;
            thc.Text = CellText;
            if (AlignOption == "L")
            {
                thc.HorizontalAlign = HorizontalAlign.Left;
            }
            else if (AlignOption == "R")
            {
                thc.HorizontalAlign = HorizontalAlign.Right;
            }
            if (ColumnWidth != 0)
            {
                thc.Width = Unit.Percentage(ColumnWidth);
            }
            TR.Controls.Add(thc);
            thc = null;
        }

        public void WebLabelNew(object PH, string LabelText, string CSSClass = "")
        {
            Label l = new Label();

            l.Text = LabelText;
            l.CssClass = CSSClass;
            (PH as Label).Controls.Add(l);

            l = null;
        }

        public string WebTextBoxInput(PlaceHolder ph, string ControlName)
        {
            TextBox tb = default(TextBox);

            tb = ph.FindControl(ControlName);
            return tb.Text;
        }

        public void WebTextBoxNew(object PH, string ID, string TextBoxText, string CSSClass = "", int Cols = -1)
        {
            TextBox t = new TextBox();

            t.Text = TextBoxText;
            t.ID = ID;
            t.CssClass = CSSClass;
            if (Cols != -1)
            {
                t.Columns = Cols;
            }
            (PH as TextBox).Controls.Add(t);
            t = null;
        }

        public DropDownList WebCellDropDownList(ref object PH, string ID)
        {
            TableCell c = new TableCell();
            DropDownList ddl = default(DropDownList);

            c.Width = 1;
            ddl = WebDropDownList(ref c, ID);
            (PH as TableCell).Controls.Add(c);
            return ddl;
        }

        public DropDownList WebDropDownList(ref object PH, string ID)
        {
            DropDownList ddl = new DropDownList();

            ddl.ID = ID;
            (PH as DropDownList).Controls.Add(ddl);
            return ddl;
        }

        public void WebDropDownListPopulate(ref DropDownList ddl, string[] values, int imax, string SelectedValue = "", string NoneSelectedValue = "")
        {
            int i = 0;

            if (!string.IsNullOrEmpty(NoneSelectedValue))
            {
                ddl.Items.Add(NoneSelectedValue);
            }
            for (i = 0; i <= imax; i++)
            {
                ddl.Items.Add(values[i]);
            }
            if (!string.IsNullOrEmpty(SelectedValue))
            {
                ddl.SelectedValue = SelectedValue;
            }
        }

        public DropDownList WebDropDownListInput(PlaceHolder ph, string ID)
        {
            DropDownList ddl = default(DropDownList);

            ddl = ph.FindControl(ID);

            return (ddl);
        }


    }
}

Open in new window

0
Chris JonesLead Application Web DeveloperAuthor Commented:
fixed a few DUH errors

Error	2	Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'. An explicit conversion exists (are you missing a cast?)	I:\Synamics\Synamics\Dynamic.cs	272	18	Synamics
Error	3	The best overloaded method match for 'Synamics.Dynamic.WebDropDownList(ref object, string)' has some invalid arguments	I:\Synamics\Synamics\Dynamic.cs	297	19	Synamics
Error	4	Argument 1: cannot convert from 'ref System.Web.UI.WebControls.TableCell' to 'ref object'	I:\Synamics\Synamics\Dynamic.cs	297	39	Synamics
Error	5	Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.DropDownList'. An explicit conversion exists (are you missing a cast?)	I:\Synamics\Synamics\Dynamic.cs	333	19	Synamics

Open in new window

0
p_davisCommented:
the second and third error -- you are passing a tablecell not an object of type object.
0
Chris JonesLead Application Web DeveloperAuthor Commented:
hmmm can you help me with an exmaple
0
p_davisCommented:
Well since you are passing on a patameter by ref you will need a local variable of type object and assign that control to it
0
Chris JonesLead Application Web DeveloperAuthor Commented:
thanks a bunch that helped me  out alot.
0
Chris JonesLead Application Web DeveloperAuthor Commented:
fast response great feedback
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.