Bind 2 DropDownList using C#

Create 2 or 3 tables in SQL,
Assign a primary key in first table(e.g. Country table).
Primary & foreign key in second table,(e.g. State Table) etc.
 
Add a connection string in web.config. 
 
Create a class file (e.g. code). 
  1. using System.Linq;  
  2. using System.Web;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. namespace WebApplication1 {  
  7.     public class code {  
  8.         SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());  
  9.         public DataSet select(string s) {  
  10.             DataSet ds = new DataSet();  
  11.             SqlDataAdapter da = new SqlDataAdapter(s, con);  
  12.             da.Fill(ds);  
  13.             return ds;  
  14.         }  
  15.         public int insert(string s) {  
  16.             int i;  
  17.             SqlCommand cmd = new SqlCommand(s, con);  
  18.             con.Open();  
  19.             i = cmd.ExecuteNonQuery();  
  20.             con.Close();  
  21.             return i;  
  22.         }  
  23.     }  
  24. }  
Code starts here: 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data;  
  8. using System.Data.SqlClient;  
  9. namespace WebApplication1 {  
  10.     public partial class DDList: System.Web.UI.Page {  
  11.         DataSet ds = new DataSet();  
  12.         code gs = new code();  
  13.         string s;  
  14.         protected void Page_Load(object sender, EventArgs e) {  
  15.             if (!IsPostBack) {  
  16.                 s = "Select * from tbl_Country"//  Table 1  
  17.                 ds = gs.select(s);  
  18.                 if (ds.Tables[0].Rows.Count > 0) {  
  19.                     DropDownList1.DataTextField = "country_name"// Country name = Column name  
  20.                     DropDownList1.DataValueField = "country_id"// Primary Key  
  21.                     DropDownList1.DataSource = ds;  
  22.                     DropDownList1.DataBind();  
  23.                     // DropDownList1.Items.Insert(0, "Select Country");  
  24.                 }  
  25.             }  
  26.         }  
  27.         protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {  
  28.             s = "select * from tbl_State where country_id = '" + DropDownList1.SelectedValue + "'"// tbl_State = Table 2  
  29.             ds = gs.select(s);  
  30.             if (ds.Tables[0].Rows.Count > 0) {  
  31.                 DropDownList2.DataTextField = "state_name";  
  32.                 DropDownList2.DataValueField = "state_id";  
  33.                 DropDownList2.DataSource = ds;  
  34.                 DropDownList2.DataBind();  
  35.                 // DropDownList2.Items.Insert(0, "Select State");  
  36.             }  
  37.         }  
  38.         protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) {  
  39.             s = "select * from tbl_city where state_id = '" + DropDownList2.SelectedValue + "'"// tbl_city = Table 3  
  40.             ds = gs.select(s);  
  41.             if (ds.Tables[0].Rows.Count > 0) {  
  42.                 DropDownList3.DataTextField = "city_name";  
  43.                 DropDownList3.DataValueField = "city_id";  
  44.                 DropDownList3.DataSource = ds;  
  45.                 DropDownList3.DataBind();  
  46.                 // DropDownList3.Items.Insert(0, "Select City");  
  47.             }  
  48.         }  
  49.     }  
  50. }  
Note: Don't forget to set AutoPostBack="true".