Hi
How is it possible to create dropdown options on the basis of another dropdown. For e.g i have 1 dropdown which lists the name of countries , i wan on the basis of country selected , list of cities of that country should appear in dropdown.
Thanks
Loading

Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 11, 2011, 1:06 AM EDT
Here is your solution using asp.net(c#)
Default.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Default.aspx.cs code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
if (!IsPostBack)
{
DropDownList_country.Items.Add("Choose country");
con.Open();
str = "select country from area group by country";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country"].ToString());
}
reader.Close();
con.Close();
}
DropDownList_state.Items.Clear();
}
protected void DropDownList_country_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from area where country='" + DropDownList_country.SelectedItem.Text + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_state.Items.Add(reader["state"].ToString());
}
reader.Close();
con.Close();
}
}
Thanks
If this post helps you mark it as answer
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 11, 2011, 1:25 AM EDT
If you need in javascript,Here is your solution i have attached.
Thanks
If this post helps you mark it as answer
Jagjit Saini166 reputationPosted Sep 11, 2011, 1:53 AM EDT
My requirement was not actually same that was e.g. I have created 1 dropdown in which i have listed Locations . On the basis of selection of Location , i want to display Offices in that location . I want this through Javscript or Json or Jquery.
Thanks
Alex Asi6 reputationPosted Oct 10, 2011, 10:28 PM EDT
http://www.magic-dev.com/ajax-filtering-cities-based-on-countries-selection.htm