search this blog [2700+ asp.net c# examples]

Loading...

Populate a DropDownList from Array data source in asp.net

DropDownList and Array example: populating a DropDownList with Array DataSource
ArrayDropDownListExample.aspx
<%@ 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 Button1_Click(object sender, System.EventArgs e) {
        string[] DataToolBoxArray = new string[13] { "ListView", "GridView", "DetailsView", "FormView", "Repeater", "DataList", "LinqDataSource", "EntityDataSource", "SqlDataSource", "AccessDataSource", "ObjectDataSource", "XmlDataSource", "SiteMapDataSource" };
        DropDownList1.DataSource = DataToolBoxArray;
        DropDownList1.DataBind();
        Label1.Text = "DataToolBox Controls<br />";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>DropDownList and Array example: populating a DropDownList with Array DataSource</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">Using Array in DropDownList</h2>
        <asp:Label ID="Label1" runat="server" Font-Bold="true" ForeColor="DarkBlue"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <br /><br />
        <asp:Button ID="Button1" runat="server" Text="Populate DropDownList" OnClick="Button1_Click" Font-Bold="true" ForeColor="DarkGreen" />
    </div>
    </form>
</body>
</html>








Related asp.net example