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("Egypt", "1"));
DropDownList1.Items.Add(new ListItem("Saudi Arabia", "2"));
DropDownList2.Enabled = false;
}
}
public void GetGovernora(string index)
{
DropDownList2.Enabled = true;
switch (index)
{
case "1":
DropDownList2.Items.Clear();
DropDownList2.Items.Add(new ListItem("Cairo","1"));
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);
}
}