Here i have explained how to bind Cascading Dropdown with Example in Asp.Net C#.

Step 1) Add HTML:

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<table>    
<tr><td align="right">Country:</td>   
<td><asp:UpdatePanel ID="countrypanel" runat="server">
<ContentTemplate><asp:DropDownList Width="150" ID="ddlcountry" AutoPostBack ="true" AppendDataBoundItems="true" runat="server" onselectedindexchanged="ddlcountry_SelectedIndexChanged"> </asp:DropDownList> 
</ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID ="ddlcountry" /></Triggers>
</asp:UpdatePanel>
</td></tr>   
<tr><td align="right">State: </td>
<td><asp:UpdatePanel ID="statepanel" runat="server">     
<ContentTemplate> <asp:DropDownList Width="150" ID="ddlstate" AutoPostBack ="true" AppendDataBoundItems ="true" runat="server" onselectedindexchanged="ddlstate_SelectedIndexChanged"> </asp:DropDownList> </ContentTemplate><Triggers> <asp:AsyncPostBackTrigger ControlID ="ddlstate"/></Triggers>  
</asp:UpdatePanel>
</td></tr>
<tr>
<td align="right">City:</td>
<td>
<asp:UpdatePanel ID="citypanel" runat="server">     
<ContentTemplate>   
<asp:DropDownList Width="150" ID="ddlcity" AutoPostBack ="true" AppendDataBoundItems ="true" runat="server" onselectedindexchanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList> </ContentTemplate> <Triggers><asp:AsyncPostBackTrigger ControlID ="ddlcity"/></Triggers>
</asp:UpdatePanel>
</td></tr>
</table>  

Step 2) Import Namespaces

using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

Step 3) C#

String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind_ddlCountry();       
}

}

public void Bind_ddlCountry()
{
SqlConnection con = new SqlConnection(ConnString);
con.Open();
SqlCommand cmd = new SqlCommand("select CountryID, CountryName from Country", con);
SqlDataReader dr = cmd.ExecuteReader();
ddlcountry.DataSource = dr;
ddlcountry.Items.Clear();
ddlcountry.Items.Insert(0, new ListItem("Select Country", "0"));
ddlcountry.DataTextField = "CountryName";
ddlcountry.DataValueField = "CountryID";
ddlcountry.DataBind();
con.Close();
}

public void Bind_ddlstate()
{
SqlConnection con = new SqlConnection(ConnString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from State where CountryID ='" + ddlcountry.SelectedValue + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
ddlstate.DataSource = dr;
ddlstate.Items.Clear();
ddlstate.Items.Insert(0, new ListItem("Select State", "0"));
ddlstate.DataTextField = "StateName";
ddlstate.DataValueField = "StateID";
ddlstate.DataBind();
con.Close();
}

public void Bind_ddlcity()
{
SqlConnection con = new SqlConnection(ConnString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from City where StateID ='" + ddlstate.SelectedValue + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
ddlcity.DataSource = dr;
ddlcity.Items.Clear();   
ddlcity.Items.Insert(0, new ListItem("Select City", "0"));
ddlcity.DataTextField = "CityName";
ddlcity.DataValueField = "CityID";
ddlcity.DataBind();
con.Close();
}

protected void ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
{
Bind_ddlstate();

}

protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
{
Bind_ddlcity();
}

protected void ddlcity_SelectedIndexChanged(object sender, EventArgs e) { }

Screenshot

Add Comments