- Simple DropdownList
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="CustName"
DataValueField="CustID">
<asp:ListItem Value="0">Please select value</asp:ListItem>
<asp:ListItem Value="1">Active</asp:ListItem>
<asp:ListItem Value="0">InActive</asp:ListItem>
</asp:DropDownList>
- Dynamic Dropdownlist
DropDownList DDLProduct = new DropDownList();
DDLProduct.Items.Add(new ListItem("---Please select value---", "-1"));
DDLProduct.Items.Add(new ListItem("Male", "1"));
DDLProduct.Items.Add(new ListItem("Female", "0"));
- To add items by using AddRange option
ListItem[] ListArr = new ListItem[4];
ListArr[0] = new ListItem() { Selected = true, Text = "India", Value = "1" };
ListArr[1] = new ListItem() { Text = "Canada", Value = "2" };
ListArr[2] = new ListItem() { Text = "US", Value = "3" };
ListArr[3] = new ListItem() { Text = "UK", Value = "4" };
DDLProduct.Items.AddRange(ListArr);
- New way of binding dropdownlist
DropDownList DDLCustomer = new DropDownList() { DataTextField="CustomerName",DataValueField="CustometID" };