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
Alex AsiPosted Oct 11, 2011, 2:28 AM
http://www.magic-dev.com/ajax-filtering-cities-based-on-countries-selection.htm
Jagjit SainiPosted Sep 11, 2011, 5:53 AM
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
Satyapriya NayakPosted Sep 11, 2011, 5:25 AM
If you need in javascript,Here is your solution i have attached.
Thanks
If this post helps you mark it as answer
Satyapriya NayakPosted Sep 11, 2011, 5:06 AM
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