C# – How to load a dropdown list in ASP.NET and C#

asp.netc

How do I load a dropdown list in asp.net and c#?

Best Answer

You can also do it declaratively:

<asp:DropDownList runat="server" ID="yourDDL">
    <asp:ListItem Text="Add something" Value="theValue" />
</asp:DropDownList>

You can also data bind them:

yourDDL.DataSource = YourIEnumberableObject;
yourDDL.DataBind();

Edit: As mentioned in the comments, you can also add items programatically:

yourDDL.Items.Add(YourSelectListItem);