This article shows how to work with a cascading dropdown list for country/state/city in ASP.Net using Entity Framework.
Create three tables as needed, as in:
- CREATE TABLE country
- (
- countryID INT NOT NULL,
- countryName varchar(50) NOT NULL,
- PRIMARY KEY (countryID ),
- );
- CREATE TABLE state
- (
- stateID INT NOT NULL,
- countryID INT NOTNULL,
- stateName varchar(50) NOT NULL,
- PRIMARY KEY (stateID ),
- FOREIGN KEY (countryID ) REFERENCES country (countryID));
- CREATE TABLE city
- (
- cityID INT NOT NULL,
- stateID INT NOTNULL,
- cityName varchar(50) NOT NULL,
- PRIMARY KEY (cityID),
- FOREIGN KEY (stateID) REFERENCES state (stateID));
First create an empty web application, as in:
Add a model as we did earlier and do the necessary

Add a web page to the solution and copy and paste this into the .aspx page:
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="cascading.aspx.cs" Inherits="counrtybasedropdown.cascading" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head id="Head1" runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <center>
- <h3>
- Cascading DropDownList for Country/State/City in ASP.Net</h3>
- <table>
- <tr>
- <td>
- Select a Country :
- </td>
- <td>
- <asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
- </asp:DropDownList>
- </td>
- </tr>
- <tr>
- <td>
- Select a State :
- </td>
- <td>
- <asp:DropDownList ID="ddlState" runat="server" Enabled="false" AutoPostBack="true" OnSelectedIndexChanged="ddlState_SelectedIndexChanged">
- </asp:DropDownList>
- </td>
- </tr>
- <tr>
- <td>
- Select a City :
- </td>
- <td>
- <asp:DropDownList ID="ddlCity" runat="server" Enabled="false">
- </asp:DropDownList>
- </td>
- </tr>
- </table>
- </center>
- </div>
- </form>
- </body>
- </html>

Elena MitevskaPosted May 31, 2017, 9:45 AM
Great article. I would like to know how can i choose more then one options from dropdown?
Upendra Pratap ShahiPosted May 1, 2016, 7:06 AM
nice..
vishnu vardhanPosted Apr 7, 2014, 10:50 AM
no i am using if condition on page load event i.e if(!Page.IsPostBack){}
Dorababu MekaPosted Apr 7, 2014, 9:23 AM
Hi as per your post I may see that you are nor binding the dropdown in page_load event with if(!ispostback){//BindCombo}
vishnu vardhanPosted Apr 7, 2014, 8:56 AM
i already posted on questions but i didn't get any thing there pls .. give me some solution
vishnu vardhanPosted Apr 7, 2014, 8:55 AM
Hello Dorababu, I am working on some project there i have 2 drop down lists and one Textbox in Update panel1. here i am binding the Names of PG from database to dropdownlist1(DDPGNames) and binding the PG rooms to dropdownlist2(DDRoomNumber) based first dropdownlist (it's like Country and state thing) now if i select any Room number in 2nd Dropdownlist the room rent has to dispaly automatically in textbox. for this i am writing this code on DDRoomNumber SelectIndexChanged Event. but my problem is DDRoomNumber is not taking selected room Number (It is taking Only First Value) if i select any other room in dropdown list it's going first one only. see here my code: protected void DDRoomNumber_SelectedIndexChanged(object sender, EventArgs e) { txtRent.Enabled = true; MySqlConnection Con = new MySqlConnection(MyConString); MySqlCommand Cmd = Con.CreateCommand(); string S = "SELECT*FROM pg_room_list WHERE Room_Num ='" DDRoomNumber.SelectedItem.Text "' AND Room_PG_ID ='" DDPGNames.SelectedValue "';"; Cmd = new MySqlCommand(S, Con); MySqlDataReader Dr; Con.Open(); Dr = Cmd.ExecuteReader(); while (Dr.Read()) { string SRoom_Rent = Dr.GetString("Room_Rent"); txtRent.Text = SRoom_Rent; } Con.Close(); } Pls give me some solution. Thanks