Saturday, June 30, 2012

how to create dynamic dropdown list in asp.net

Here in this post i will show how to create a drop down list and add items dynamically in asp.net.We  can do this functionality in two ways one is using List  and other one is directly adding the items to drop down.The "ddllist"  is the list which will be bind to drop down list
Usign list to bind  items to dropdownlist:
DropDownList ddlcountry = new DropDownList();
List<string> ddllist = new List<string>();
ddllist.Add("India");
ddllist.Add("us");
ddllist.Add("uk");
ddlcountry.DataSource = ddllist;
dddlcountry.DataBind();
this.Controls.Add(ddlcountry);

Simple item binding to dropdownlist:
DropDownList ddlcity = new DropDownList();
ddlcity.Items.Add("Hydreabad");
ddlcity.Items.Add("Mumbai");
ddlcity.Items.Add("chennai");
this.Controls.Add(ddlcity);

No comments:

Bel