We can define array of list items to the dropdownlist in code behind
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
ListItem[] li = new ListItem[4];
{
new ListItem("AP","1");
new ListItem("UP","2");
new ListItem("MP","3");
new ListItem("TS","4");
}
DropDownList1.Items.AddRange(li);
//INSERT AN ITEM AS LISTITEM AT ZERO INDEX
DropDownList1.Items.Insert(0, new ListItem("Select State", "0"));
//or
DropDownList1.Items.AddRange(new ListItem[]
{
new ListItem("AP"),
new ListItem("UP"),
new ListItem("MP"),
new ListItem("TS"),
new ListItem("Tamilnadu")
});
//INSERT AN ITEM AS LISTITEM AT ZERO INDEX
DropDownList1.Items.Insert(0, new ListItem("Select State", "0"));
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
ListItem[] li = new ListItem[4];
{
new ListItem("AP","1");
new ListItem("UP","2");
new ListItem("MP","3");
new ListItem("TS","4");
}
DropDownList1.Items.AddRange(li);
//INSERT AN ITEM AS LISTITEM AT ZERO INDEX
DropDownList1.Items.Insert(0, new ListItem("Select State", "0"));
//or
DropDownList1.Items.AddRange(new ListItem[]
{
new ListItem("AP"),
new ListItem("UP"),
new ListItem("MP"),
new ListItem("TS"),
new ListItem("Tamilnadu")
});
//INSERT AN ITEM AS LISTITEM AT ZERO INDEX
DropDownList1.Items.Insert(0, new ListItem("Select State", "0"));
}
}
No comments:
Post a Comment