
This code shows how to create two DropDownList controls where selecting an item in the first list populates the items in the second list।
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add(new ListItem("Select Country", "0"));
DropDownList1.Items.Add(new ListItem("
DropDownList1.Items.Add(new ListItem("
DropDownList2.Enabled = false;
}
}
public void GetGovernora(string index)
{
DropDownList2.Enabled = true;
switch (index)
{
case "1":
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("
DropDownList2.Items.Add(new ListItem("Alex","2"));
DropDownList2.Items.Add(new ListItem("Mansoura","3"));
DropDownList2.Items.Add(new ListItem("Domiatta","4"));
break;
case "2":
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("Ryiad","1"));
DropDownList2.Items.Add(new ListItem("Gada", "2"));
DropDownList2.Items.Add(new ListItem("Jezan", "3"));
break;
default:
DropDownList2.Items.Clear();
DropDownList2.Items.Add("No Avaliable Country");
DropDownList2.Enabled = false;
break;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GetGovernora(DropDownList1.SelectedValue);
}
}


0 التعليقات:
إرسال تعليق