Bind a Dropdownlist in ASP.NET


    Items to the dropdownlist can be added programmatically using ListItem class.
The below example shows adding of values to dropdownlist  in the program.

Populate Dropdownlist from Database

<%@ Page Language="C#" %>

<!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 Page_Load(object sender, EventArgs e)
    {
        DropDownList1.Items.Add(new ListItem("Apples", "1", true));
        DropDownList1.Items.Add(new ListItem("Mangoes", "2"));
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Dropdownlist</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>