How to add Items in Dropdown list programatically ??
Hi,
There is two dropdown list on page. One is for State and second one is for City related to that sate only.
I have addded the Name of state in first dropdownlist and would like to write programming in such a way so
that when I select the name of state the city related to that state adds automatically in second dropdownlist.
I tried many code but all are giving error.
like
protected void State_DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
if (State_DropDownList.SelectedItem.Text == "Bihar")
{
City_DropDownList.Items.Add("Patna");
City_DropDownList.Items.Add("Gaya");
City_DropDownList.Items.Add("Aurangabad");
}
}
protected void State_DropDownList_TextChanged(object sender, EventArgs e)
{
if (State_DropDownList.SelectedItem.Text == "Bihar")
{
City_DropDownList.Items.Add("Patna");
City_DropDownList.Items.Add("Gaya");
City_DropDownList.Items.Add("Aurangabad");
}
Post back is enable for both Dropdown list
but these codes are not working please help me.
I do not want to use database for that.
|