Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
selected value in dropdownlist(state) if person select any state then in another dropdownlist show city regarding the selected city in another dropdownlist in asp.net
Posted
Comments
ridoy 22-Aug-12 6:03am    
simple solution..do you try it by yourself? not expect code from here..this willnot increase your programming skill

Please check
DropDownList with country, state and city in ASP. NET[^]
and
Country State City DropdownList Using Asp .Net(C#)
[^].

These show exactly what you need.
Happy coding...
 
Share this answer
 
Make the dropdownlist(state) AutoPostBack property to True. Then in selected IndexChanged event take the value of dropdownlist(state) and retrieve the City List from database by supplying selected state. Then bind the city list result with another dropdownlist.
 
Share this answer
 
hi Manish
go through this link hope you will get what you want

http://www.c-sharpcorner.com/uploadfile/rohatash/dropdownlist-with-country-state-and-city-in-asp-net/[^]

cheers
Prafulla
 
Share this answer
 
I don't understand why you ask same question within 2 hours?Doesn't it solve your problem..?
selected value in dropdownlist and then show velue in another dropdownlist in asp.net[^]
 
Share this answer
 
C#
protected void CountryBind()
    {
        string sqlQuery = "Select * from Country";

        using (SqlConnection conn = new SqlConnection(conString))
        {
            conn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(sqlQuery, conn);
            da.Fill(ds);
            ddlCountry.DataSource = ds;
            ddlCountry.DataBind();
            conn.Close();
        }
    }


C#
protected void StateBind()
{
    string sqlQuery = "SELECT * FROM State " + " WHERE (CountryId = " + Convert.ToInt32(ddlCountry.SelectedValue) + " )";

    using (SqlConnection conn = new SqlConnection(conString))
    {
        conn.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sqlQuery, conn);
        da.Fill(ds);
        ddlState.DataSource = ds;
        ddlState.DataBind();
        conn.Close();
    }
}


C#
protected void CityBind()
{
    string sqlQuery = "SELECT * FROM City " + " WHERE (StateId = " + Convert.ToInt32(ddlState.SelectedValue) + " )";

    using (SqlConnection conn = new SqlConnection(conString))
    {
        conn.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sqlQuery, conn);
        da.Fill(ds);
        ddlCity.DataSource = ds;
        ddlCity.DataBind();
        conn.Close();
    }
}

C#
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
    StateBind();
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
    CityBind();
}
 
Share this answer
 
v2
Comments
Kuthuparakkal 22-Aug-12 23:45pm    
Markups:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

State
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged1">

City
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900