{"id":4971,"date":"2024-03-02T05:58:27","date_gmt":"2024-03-02T05:58:27","guid":{"rendered":"https:\/\/isophal.com\/?p=4971"},"modified":"2024-03-02T05:58:29","modified_gmt":"2024-03-02T05:58:29","slug":"dropdownlist-with-country-state-and-city-in-asp-net","status":"publish","type":"post","link":"https:\/\/isophal.com\/news\/2024\/03\/02\/4971.html\/","title":{"rendered":"DropDownList With Country, State And City In ASP. NET"},"content":{"rendered":"\n<p>This article shows how to create three DropDownList to display countries, states and cities. When you select a country then its automatically shows the states name of that country in next DropDownList. Then when you select a state, the cities DropDownList will fetch the related cities for that state.<\/p>\n\n\n\n<p>Creating table for country, state and city.<\/p>\n\n\n\n<p><strong>Country Table<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>Create<\/strong>&nbsp;<strong>Table<\/strong>&nbsp;Country&nbsp;&nbsp;<\/li>\n\n\n\n<li>(&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;CountryId&nbsp;<strong>Int<\/strong>&nbsp;<strong>Primary<\/strong>&nbsp;<strong>Key<\/strong>,&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;County&nbsp;<strong>Varchar<\/strong>(30)&nbsp;&nbsp;<\/li>\n\n\n\n<li>)&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>Countrystate Table<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>Create<\/strong>&nbsp;<strong>Table<\/strong>&nbsp;countryState&nbsp;&nbsp;<\/li>\n\n\n\n<li>(&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;StateId&nbsp;<strong>Int<\/strong>&nbsp;<strong>Primary<\/strong>&nbsp;<strong>Key<\/strong>,&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;CountryId&nbsp;<strong>Int<\/strong>&nbsp;<strong>Foreign<\/strong>&nbsp;<strong>Key<\/strong>&nbsp;<strong>References<\/strong>&nbsp;Country(CountryId),&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;State&nbsp;<strong>Varchar<\/strong>(30)&nbsp;&nbsp;<\/li>\n\n\n\n<li>)&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>StateCity Table<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>Create<\/strong>&nbsp;<strong>Table<\/strong>&nbsp;stateCity&nbsp;&nbsp;<\/li>\n\n\n\n<li>(&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;CityId&nbsp;<strong>Int<\/strong>,&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;StateId&nbsp;<strong>Int<\/strong>&nbsp;<strong>Foreign<\/strong>&nbsp;<strong>Key<\/strong>&nbsp;<strong>References<\/strong>&nbsp;countryState(StateId),&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;City&nbsp;<strong>Varchar<\/strong>(30)&nbsp;&nbsp;<\/li>\n\n\n\n<li>)&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Now insert values in the table.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;Country&nbsp;<strong>Values<\/strong>(101,&#8217;India&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;Country&nbsp;<strong>Values<\/strong>(102,&#8217;USA&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;Country&nbsp;<strong>Values<\/strong>(103,&#8217;Pakistan&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(1001,101,&#8217;U.P&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(1002,101,&#8217;Kerala&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(1003,101,&#8217;Kasmir&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(2001,102,&#8217;Colorado&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(2002,102,&#8217;Delaware&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(2003,102,&#8217;Georgia&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(3001,103,&#8217;Punjap&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(3002,103,&#8217;Baluchistan&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;countryState&nbsp;<strong>Values<\/strong>(3003,103,&#8217;Sind&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(11,1001,&#8217;Kanpur&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(12,1001,&#8217;Dg&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(21,1002,&#8217;Pal&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(22,1002,&#8217;Tri&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(31,1003,&#8217;Jammu&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(32,1003,&#8217;Manali&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(41,2001,&#8217;Alabama&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(42,2001,&#8217;Arizona&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(51,2002,&#8217;Bellefonte&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(52,2002,&#8217;Felton&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(61,2003,&#8217;Rustavi&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(62,2003,&#8217;Kobulati&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(71,3001,&#8217;Lahore&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(72,3001,&#8217;Faisalabad&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(81,3002,&#8217;Quetta&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(82,3002,&#8217;Nasirabad&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(91,3003,&#8217;Krachi&#8217;)&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>Insert<\/strong>&nbsp;<strong>Into<\/strong>&nbsp;stateCity&nbsp;<strong>Values<\/strong>(92,3003,&#8217;Mirpur&nbsp;khas&#8217;)&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Now select it.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>select<\/strong>&nbsp;*&nbsp;<strong>from<\/strong>&nbsp;Country; &nbsp;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/countrytable.gif\" alt=\"countrytable.gif\"\/><\/figure>\n\n\n\n<p>Countrytable<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>select<\/strong>&nbsp;*&nbsp;<strong>from<\/strong>&nbsp;&nbsp;countryState; &nbsp;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/citytable.gif\" alt=\"citytable.gif\"\/><\/figure>\n\n\n\n<p>Statetable<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>select<\/strong>&nbsp;*&nbsp;<strong>from<\/strong>&nbsp;stateCity;&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/statetable.gif\" alt=\"statetable.gif\"\/><\/figure>\n\n\n\n<p>Citytable<\/p>\n\n\n\n<p>Now drag and drop three DropDownList to display countries, states and cities and three update panel control on the page.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/fig1.gif\" alt=\"fig1.gif\"\/><\/figure>\n\n\n\n<p>Figure1<\/p>\n\n\n\n<p><strong>.aspx code<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>&lt;headrunat=&#8221;server&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&lt;title&gt;&lt;\/title&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;\/head&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;body&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&lt;formid=&#8221;form1&#8243;runat=&#8221;server&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&lt;asp:ScriptManagerID=&#8221;ScriptManager1&#8243;runat=&#8221;server&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&lt;\/asp:ScriptManager&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&lt;div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:UpdatePanelID=&#8221;countrypanel&#8221;runat=&#8221;server&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ContentTemplate&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;spanclass=&#8221;style1&#8243;&gt;&lt;strong&gt;Select&nbsp;Country:&lt;\/strong&gt;&lt;\/span&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:DropDownListID=&#8221;ddlcountry&#8221;AutoPostBack&nbsp;=&#8221;true&#8221;&nbsp;AppendDataBoundItems&nbsp;&nbsp;<\/li>\n\n\n\n<li>=&#8221;true&#8221;&nbsp;runat=&#8221;server&#8221;Height=&#8221;20px&#8221;Width=&#8221;156px&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>onselectedindexchanged=&#8221;ddlcountry_SelectedIndexChanged&#8221;BackColor=&#8221;#3399FF&#8221;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ForeColor=&#8221;#FF9999&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/asp:DropDownList&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/ContentTemplate&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Triggers&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:AsyncPostBackTriggerControlID&nbsp;=&#8221;ddlcountry&#8221;&nbsp;\/&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Triggers&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&lt;\/asp:UpdatePanel&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br\/&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&lt;asp:UpdatePanelID=&#8221;statepanel&#8221;runat=&#8221;server&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;ContentTemplate&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;spanclass=&#8221;style1&#8243;&gt;&lt;strong&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select&nbsp;State:&lt;\/strong&gt;&lt;\/span&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:DropDownListID=&#8221;ddlstate&#8221;AutoPostBack&nbsp;=&#8221;true&#8221;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AppendDataBoundItems=&#8221;true&#8221;&nbsp;&nbsp;runat=&#8221;server&#8221;Height=&#8221;20px&#8221;&nbsp;&nbsp;<\/li>\n\n\n\n<li>Width=&#8221;155px&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onselectedindexchanged=&#8221;ddlstate_SelectedIndexChanged&#8221;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BackColor=&#8221;#FF3399&#8243;ForeColor=&#8221;Maroon&#8221;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/asp:DropDownList&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/ContentTemplate&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Triggers&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:AsyncPostBackTriggerControlID&nbsp;=&#8221;ddlstate&#8221;\/&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Triggers&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/asp:UpdatePanel&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br\/&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;asp:UpdatePanelID=&#8221;citypanel&#8221;runat=&#8221;server&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&lt;ContentTemplate&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;spanclass=&#8221;style1&#8243;&gt;&lt;strong&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select&nbsp;City:&lt;\/strong&gt;&lt;\/span&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:DropDownListID=&#8221;ddlcity&#8221;&nbsp;AutoPostBack&nbsp;=&#8221;true&#8221;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;AppendDataBoundItems=&#8221;true&#8221;&nbsp;runat=&#8221;server&#8221;Height=&#8221;20px&#8221;Width=&#8221;155px&#8221;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BackColor=&#8221;#66FFFF&#8221;ForeColor=&#8221;#006666&#8243;&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/asp:DropDownList&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&lt;\/ContentTemplate&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&lt;Triggers&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:AsyncPostBackTrigger&nbsp;ControlID&nbsp;=&#8221;ddlcity&#8221;\/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Triggers&gt;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&lt;\/asp:UpdatePanel&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&lt;\/div&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&lt;\/form&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;\/body&gt;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&lt;\/html&gt; &nbsp;<\/li>\n<\/ol>\n\n\n\n<p><strong>.VB code<\/strong>&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>using&nbsp;System;&nbsp;&nbsp;<\/li>\n\n\n\n<li>using&nbsp;System.Collections.Generic;&nbsp;&nbsp;<\/li>\n\n\n\n<li>using&nbsp;System.Linq;&nbsp;&nbsp;<\/li>\n\n\n\n<li>using&nbsp;System.Web;&nbsp;&nbsp;<\/li>\n\n\n\n<li>using&nbsp;System.Web.UI;&nbsp;&nbsp;<\/li>\n\n\n\n<li>using&nbsp;System.Web.UI.WebControls;&nbsp;&nbsp;<\/li>\n\n\n\n<li>using&nbsp;System.Data.SqlClient;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>namespace&nbsp;CountryStateCity&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;partialclass&nbsp;WebForm1&nbsp;:&nbsp;System.Web.UI.Page&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>private<\/strong>&nbsp;SqlConnection&nbsp;conn&nbsp;=&nbsp;<strong>new<\/strong>&nbsp;SqlConnection(&#8220;Data&nbsp;source=.;&nbsp;uid=sa;&nbsp;&nbsp;&nbsp;pwd=Password$2;&nbsp;database=CountryStateCity&#8221;);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>void<\/strong>&nbsp;Bind_ddlCountry()&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.Open();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlCommand&nbsp;cmd&nbsp;=<strong>new<\/strong>&nbsp;SqlCommand(&#8220;select&nbsp;County,CountryId&nbsp;from&nbsp;Country&#8221;,&nbsp;conn);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlDataReader&nbsp;dr&nbsp;=&nbsp;cmd.ExecuteReader();&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcountry.DataSource&nbsp;=&nbsp;dr;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcountry.Items.Clear();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcountry.Items.Add(&#8220;&#8211;Please&nbsp;Select&nbsp;country&#8211;&#8220;);&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcountry.DataTextField&nbsp;=&nbsp;&#8220;County&#8221;;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcountry.DataValueField&nbsp;=&nbsp;&#8220;CountryId&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcountry.DataBind();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.Close();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>void<\/strong>&nbsp;Bind_ddlState()&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.Open();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlCommand&nbsp;cmd&nbsp;=<strong>new<\/strong>&nbsp;SqlCommand(&#8220;select&nbsp;State,StateID&nbsp;from&nbsp;countryState&nbsp;where&nbsp;CountryId='&#8221;&nbsp;+&nbsp;ddlcountry.SelectedValue&nbsp;+&#8221;&#8216;&#8221;,&nbsp;conn);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlDataReader&nbsp;dr&nbsp;=&nbsp;cmd.ExecuteReader();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlstate.DataSource&nbsp;=&nbsp;dr;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlstate.Items.Clear();&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlstate.Items.Add(&#8220;&#8211;Please&nbsp;Select&nbsp;state&#8211;&#8220;);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlstate.DataTextField&nbsp;=&nbsp;&#8220;State&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlstate.DataValueField&nbsp;=&nbsp;&#8220;StateID&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlstate.DataBind();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.Close();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>void<\/strong>&nbsp;Bind_ddlCity()&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.Open();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlCommand&nbsp;cmd&nbsp;=<strong>new<\/strong>&nbsp;SqlCommand(&#8220;select&nbsp;*&nbsp;from&nbsp;stateCity&nbsp;where&nbsp;StateId&nbsp;='&#8221;&nbsp;+&nbsp;ddlstate.SelectedValue&nbsp;+&#8221;&#8216;&#8221;,&nbsp;conn);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlDataReader&nbsp;dr&nbsp;=&nbsp;cmd.ExecuteReader();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcity.DataSource&nbsp;=&nbsp;dr;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcity.Items.Clear();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcity.Items.Add(&#8220;&#8211;Please&nbsp;Select&nbsp;city&#8211;&#8220;);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcity.DataTextField&nbsp;=&nbsp;&#8220;City&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcity.DataValueField&nbsp;=&nbsp;&#8220;CityID&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ddlcity.DataBind();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.Close();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protectedvoid&nbsp;Page_Load(object&nbsp;sender,&nbsp;EventArgs&nbsp;e)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>if<\/strong>&nbsp;(!IsPostBack)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bind_ddlCountry();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protectedvoid&nbsp;ddlcountry_SelectedIndexChanged(object&nbsp;sender,&nbsp;EventArgs&nbsp;e)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bind_ddlState();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protectedvoid&nbsp;ddlstate_SelectedIndexChanged(object&nbsp;sender,&nbsp;EventArgs&nbsp;e)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bind_ddlCity();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;} &nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Now run the application and test it.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/fig2.gif\" alt=\"fig2.gif\"\/><\/figure>\n\n\n\n<p>Figure2<\/p>\n\n\n\n<p>Now select a country, then its automatically shows the states name of that country in next DropDownList. For example we select USA.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/fig3.gif\" alt=\"fig3.gif\"\/><\/figure>\n\n\n\n<p>Figure3<\/p>\n\n\n\n<p>Now select a State, then its automatically shows the cities name of that state in next DropDownList. For example we select Punjab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/rohatash\/dropdownlist-with-country-state-and-city-in-asp-net\/Images\/fig4.gif\" alt=\"fig4.gif\"\/><\/figure>\n\n\n\n<p>Figure4<\/p>\n\n\n\n<p><strong><u>Note<br><\/u><\/strong><br>You can see a demo of this article by downloading this application.<\/p>\n\n\n\n<p>Download Source Code <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows how to create three&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4972,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189,140],"tags":[191],"class_list":["post-4971","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net","category-programming","tag-asp-net"],"_links":{"self":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/comments?post=4971"}],"version-history":[{"count":1,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4971\/revisions"}],"predecessor-version":[{"id":4973,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4971\/revisions\/4973"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media\/4972"}],"wp:attachment":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media?parent=4971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/categories?post=4971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/tags?post=4971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}