ASP dropdownlist databind from database
<p>I am using 2 dropdownlist. 1st for country and 2nd for states. If I select India from 1ft dropdownlist, the 2nd one is automatically bind all the states of India automatically from database.</p>

<p>I have used <code>country_tbl</code> for countries and bind with 1st dropdownlist and <code>india_tbl</code>, <code>us_tbl</code>, <code>sri_tbl</code> for binding states regarding these countries.</p>

<p>Please help me. What should I do?</p>

<p>My code is as follows:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        method1();
    }
}

protected void method1()
{
    string s1 = "data source=ALOK-PC\\SQLEXPRESS;database=MySite;integrated security=true";
    SqlConnection con = new SqlConnection(s1);
    string s2 = "select * from country";
    SqlCommand cmd = new SqlCommand(s2, con);
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    DropDownList1.DataTextField = "name";
    DropDownList1.DataValueField = "name";
    DropDownList1.DataSource = dr;
    DropDownList1.DataBind();
    con.Close();
    dr.Close();
}

protected void methodInd()
{
    string s1 = "data source=ALOK-PC\\SQLEXPRESS;database=MySite;integrated security=true";
    SqlConnection con = new SqlConnection(s1);
    string s2 = "select * from india";
    SqlCommand cmd = new SqlCommand(s2, con);
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    DropDownList2.DataTextField = "name";
    DropDownList2.DataValueField = "name";
    DropDownList2.DataSource = dr;
    DropDownList2.DataBind();
    con.Close();
    dr.Close();
}

protected void methodpak()
{
    string s1 = "data source=ALOK-PC\\SQLEXPRESS;database=MySite;integrated security=true";
    SqlConnection con = new SqlConnection(s1);
    string s2 = "select * from pakistan";
    SqlCommand cmd = new SqlCommand(s2, con);
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    DropDownList2.DataTextField = "name";
    DropDownList2.DataValueField = "name";
    DropDownList2.DataSource = dr;
    DropDownList2.DataBind();
    con.Close();
    dr.Close();
}

protected void methodsri()
{
    string s1 = "data source=ALOK-PC\\SQLEXPRESS;database=MySite;integrated security=true";
    SqlConnection con = new SqlConnection(s1);
    string s2 = "select * from srilanka";
    SqlCommand cmd = new SqlCommand(s2, con);
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    DropDownList2.DataTextField = "name";
    DropDownList2.DataValueField = "name";
    DropDownList2.DataSource = dr;
    DropDownList2.DataBind();
    con.Close();
    dr.Close();
}

protected void submit_Click(object sender, EventArgs e)
{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (DropDownList1.SelectedItem.Text=="india")
    {
        methodInd();
    }
    else if (DropDownList1.SelectedItem.Text=="pakistan")
    {
        methodpak();
    }
    else if (DropDownList1.SelectedItem.Text=="srilanka")
    {
        methodsri();
    }
}
</code></pre>
