Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2007, 06:14 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default select country in drop down and state accordingly

Hi, i have 2 dropdownlist and i want when i select country from first drop down second drop down should show the states of that country.
i had made 2 tables - one is country and other is states.
country has 2 column - country_id and country_name
state has 3 column - state_id, country_id and state_name.

country id in state table is as fk .

and i am trying this ,, plz help me---

string id = ddlcountry.SelectedValue;
           string qry = "select State_Name from State where Country_ID=(Select Country_ID from Country where Country_Name='" + id +"')";
            SqlDataAdapter adp = new SqlDataAdapter(qry,con);
            DataSet ds = new DataSet();
            adp.Fill(ds);

            ddlstate.DataValueField = "State_Name";
            ddlstate.DataSource = ds;
            ddlstate.DataBind();

 
Old September 10th, 2007, 06:28 AM
Registered User
 
Join Date: Aug 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi try this




string id = ddlcountry.Selecteditem.value; //Gets the selected countrie's id
 string qry = "select State_Name from State where Country_ID=" + id ;
            SqlDataAdapter adp = new SqlDataAdapter(qry,con);
            DataSet ds = new DataSet();
            adp.Fill(ds);

            ddlstate.DataValueField = "State_ID";
            ddlstate.DataTextField = "State_Name";
            ddlstate.DataSource = ds;
            ddlstate.DataBind();


gudluck


Archu
 
Old September 11th, 2007, 04:22 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys,

I'm working on a similar thing, but I have 4 Dropdown menus, with the contents of a dropdown being populated from the previous.

Am I right in assuming I can use a similar process with more Dropdowns?

I just want to get the idea right and give it a go at coding it myself first (No doubt there will eb a reply when i get stuck :D)

Cheers

 
Old September 11th, 2007, 08:54 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You surely can. And with AJAX you can make it very clean and fast.

-Peter
 
Old September 11th, 2007, 09:42 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

To add to Peter's point, you can check some wonderful controls of AJAX live at:

http://www.asp.net/ajax/control-toolkit/live/

Regards
Mike





Similar Threads
Thread Thread Starter Forum Replies Last Post
selective validation Country/State dsmportal ASP.NET 2.0 Professional 3 August 9th, 2006 04:01 PM
selective validation Country/State dsmportal ASP.NET 1.0 and 1.1 Professional 0 August 3rd, 2006 12:35 PM
disabling drop-down menu (select) crmpicco Javascript How-To 2 March 1st, 2005 07:08 AM
drop down select box shoakat Classic ASP Databases 1 February 10th, 2005 04:42 AM
Tip! Drop down "State", "Country" selections larry HTML Code Clinic 0 January 1st, 2004 11:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.