C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Dropdownlist box in asp.net


Posted Date: 28 Jul 2008      Total Responses: 5

Posted By: geetharam       Member Level: Bronze     Points: 1



hi,

I am doing a project in asp.net with sql...In one of my page i have two dropdown list boxes named country and city...All the name of the countries and cities are stored in database...My pbl is,if i choose a country the cities related or included in that particular country alone should be loaded in city dropdown list control..can anyone plz help





Responses

Author: Sabu C Alex    28 Jul 2008Member Level: GoldRating:     Points: 4

hi geetharam

What you have to do is

in the first dropdown list's selectedindexchaged event
ie:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//Write code for binding data to second dropdownlist
}

Here write the code for adding data to second dropdownlist.



Author: muralidhar    28 Jul 2008Member Level: GoldRating:     Points: 5

hai,

i think you are getting the citites in the selected country.

you are doing mistake when populating then dropdownlist.

lets take two dropdownlists ddlCountry and ddlCities

in ddlCountry selectedindexchanged event get all the cities for that country and bind the cities to ddlCities.

loop in dataset or datareader and place the below lines in that loop
ddlCities.Items.Clear();
ddlCities.Items.Add(<dataset item or datareader item>);


regards,
Muralidhar.



Author: Mexi Renjith Mamman    28 Jul 2008Member Level: GoldRating:     Points: 4


Is your problem is not showing cities related to selected country?

If it is you have to do like this:

First fill the dropdown of country and in the selected Index Changed event of that dropdown , take the selectedItem.Value of the Country and fill the dropdown for Cities with that selected value of country.

The dropdown of cities will be filled based on the selected Country.



Author: G.Hemadribabu    28 Jul 2008Member Level: GoldRating:     Points: 6

your requirement is on selection of country dd , that corresponding sitys shoudl be displayed in city dd . so

write the query in country dropdown box like this, (Give autopostback = true)
select country coulmn, city column from table name where countrycolumn name = dd1.selectedvalue

and fill the results in city dropdown box,

This will surely work try it,

IF you need exact code, then tell me the columns name,table name and dropdown box's name,
i will modify and send you teh code back

hopw thiswill work ,
takecare



Author: Raghuramakarthikeyan    28 Jul 2008Member Level: GoldRating:     Points: 6

Solution:
In the Database you store as State and city like this:
Table Name StateTable:
State City
Tamilnadu chennai
Tamilnadu Trichy
Karnataka Bangalore
Karnataka Mysore

Like this and then write this query
Select State From StateTable
with this Fill the Drop Down
and also make THe first dropdown Autopostback as true..
after selecting the first dropdown
write the code in selectedindexchanged of first drop down,
Select City from StateTable Where State='Tamilnadu'
you will get the cities of tamil nadu



Post Reply
You must Sign In to post a response.
Next : How to access items in datagrid?
Previous : Ajax...
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use