Home ProgrammingASP.NET Populate DropDownList Dynamically in ASP.NET (Country-State-District-City)

Populate DropDownList Dynamically in ASP.NET (Country-State-District-City)

by John Bhatt
417 views
How to Make a Complete Dropdown and Prevent Inserting Dummy Data from Form.
Disable other Controls when Clicked back to Parent Control:
Drop Down Sequence:
OnLoad
Load Country
On-Change
Load State according to Country
On-Change
Load Dists in State
On-Change
List Cities in Dist.
Code:
[csharp]
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
ddlState.DataSource = res.States(Convert.ToInt16(ddlCountry.SelectedValue));
ddlState.DataTextField = “StateName”;
ddlState.DataValueField = “StateID”;
ddlState.DataBind();
ddlState.Items.Insert(0, “Select”);
ddlDist.Enabled = false;
ddlCity.Enabled = false;
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e){
ddlDist.DataSource = res.Districts(Convert.ToInt16(ddlState.SelectedValue));
ddlDist.DataTextField = “DistName”;
ddlDist.DataValueField = “DistID”;
ddlDist.DataBind();
ddlDist.Items.Insert(0, “Select”);
ddlDist.Enabled = true;
ddlCity.Enabled = false;
}
protected void ddlDist_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.DataSource = res.Cities(Convert.ToInt16(ddlDist.SelectedValue));
ddlCity.DataTextField = “CityName”;
ddlCity.DataValueField = “CityID”;
ddlCity.DataBind();
ddlCity.Items.Insert(0, “Select”);
ddlCity.Enabled = true;
}
[/csharp]
Preview:

John Bhatt
Glad to Know, Free to Share…..
http://www.johnbhatt.com

You may also like

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Populate DropDownList Dynamically in ASP.NET (Country-State-District-City)

by John Bhatt time to read: 1 min
0