If you want to bind the Country and State and City in asp.net .....follow these Steps
1. Open Visual Studio 2010
2. New Project
3. And .aspx page Design will be like this or as per as your requirement
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="statebinding.aspx.cs" Inherits="WebApplication1.statebinding" %>
<!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 runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
height: 62px;
}
.style2
{
width: 202px;
}
.style3
{
width: 202px;
height: 34px;
}
.style4
{
height: 34px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<table class="style1">
<tr>
<td>
<asp:Label ID="lblCountry" runat="server" Text="Country"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="23px" Width="153px"
onselectedindexchanged="DropDownList1_SelectedIndexChanged1">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblState" runat="server" Text="State"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" Height="22px" Width="152px"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
<table class="style1">
<tr>
<td class="style3">
<asp:Label ID="lblCity" runat="server" Text="City"></asp:Label>
</td>
<td class="style4">
<asp:DropDownList ID="DropDownList3" runat="server" Height="28px"
style="margin-left: 3px" Width="151px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
4.And Now Do the Code for aspx.cs File...............
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1
{
public partial class statebinding : System.Web.UI.Page
{
// public string str="Data Source=PANKAJ-PC\\SQLEXPRESS2008;Initial Catalog=Data;User ID=sa;Password=sa2008";
private SqlConnection con = new SqlConnection("Data Source=PANKAJ-PC\\SQLEXPRESS2008;Initial Catalog=Data;User ID=sa;Password=sa2008");
public void BindCountry()
{
con.Open();
SqlCommand com = new SqlCommand("Select County,CountryId from Country",con);
SqlDataReader ds = com.ExecuteReader();
DropDownList1.DataSource = ds;
DropDownList1.Items.Clear();
DropDownList1.Items.Add("--Please Select Country--");
DropDownList1.DataTextField = "County";
DropDownList1.DataValueField = "CountryId";
DropDownList1.DataBind();
con.Close();
}
public void BindState()
{
con.Open();
SqlCommand com1 = new SqlCommand("select State,StateId from countryState where CountryId='" + DropDownList1.SelectedValue +"'", con);
SqlDataReader rd = com1.ExecuteReader();
DropDownList2.DataSource = rd;
DropDownList2.Items.Clear();
DropDownList2.Items.Add("--Please select State--");
DropDownList2.DataTextField = "State";
DropDownList2.DataValueField = "StateId";
DropDownList2.DataBind();
con.Close();
}
public void citybind()
{
con.Open();
SqlCommand com2 = new SqlCommand("Select * from stateCity where StateId='"+DropDownList2.SelectedValue+"'",con);
SqlDataReader dr = com2.ExecuteReader();
DropDownList3.DataSource = dr;
DropDownList3.Items.Clear();
DropDownList3.Items.Add("--Please select City--");
DropDownList3.DataTextField = "City";
DropDownList3.DataValueField = "CityId";
DropDownList3.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCountry();
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
citybind();
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
BindState();
}
}
}
If you face any problem then Send feedback to me ............Thanks