How to use DropDownList OnDataBinding event in asp.net c#

How to use DropDownList OnDataBinding event in asp.net
DropDownListOnDataBindingEvent.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        string[] colors = { "DarkOrchid", "DarkViolet", "DodgerBlue", "GhostWhite", "GreenYellow" };
        DropDownList1.DataSource = colors;
        DropDownList1.DataBind();
    }

    protected void DropDownList1_DataBinding(object sender, EventArgs e)
    {
        Label1.Text = "Choose your favorite color: ";
        Label1.ForeColor = System.Drawing.Color.DodgerBlue;
        Label1.Font.Name = "Comic Sans MS";
        Label1.Font.Italic = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use DropDownList OnDataBinding event in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkOrchid; font-style:italic;">
            How to use DropDownList
            <br /> OnDataBinding event in asp.net
        </h2>
        <hr width="350" align="left" color="Orchid" />
        <asp:Label 
            ID="Label1" 
            runat="server"
            >
        </asp:Label>
        <asp:DropDownList 
            ID="DropDownList1"
            runat="server"
            ForeColor="SkyBlue"
            Font-Size="Large"
            OnDataBinding="DropDownList1_DataBinding"
            >
        </asp:DropDownList>
        <br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Populate DropDownList"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>








Related asp.net example