asp.net - How to add a DropDownList in a PlaceHolder

How to add a DropDownList control in PlaceHolder programmatically
PlaceHolderAddDropDownList.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        String[] ControlList = { "HiddenField", "Calendar", "ImageMap", "Label", "Literal" };
        DropDownList DropDownList1 = new DropDownList();
        DropDownList1.BorderWidth = 2;
        DropDownList1.BorderColor = Color.SkyBlue;
        DropDownList1.BackColor = Color.AliceBlue;
        DropDownList1.ForeColor = Color.DeepPink;
        DropDownList1.Font.Italic = true;
        DropDownList1.Font.Size = FontUnit.Large;
        DropDownList1.Font.Name = "Comic Sans MS";
        DropDownList1.Width = 250;
        DropDownList1.DataSource = ControlList;
        DropDownList1.DataBind();
        PlaceHolder1.Controls.Add(DropDownList1);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to add a DropDownList control in PlaceHolder programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">PlaceHolder Example: Add DropDownList</h2>
        <br />
        <asp:PlaceHolder 
             ID="PlaceHolder1"
             runat="server"
             >
        </asp:PlaceHolder>
        <br /><br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DarkBlue"
             Text="Add DropDownList Control"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>








Related asp.net example