Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ddl selected index change

Status
Not open for further replies.

shaminoo

Programmer
Aug 28, 2006
7
US
Hi experts
I am makin a .net web application..on page.aspx i ve 2 ddl of states and cities.When i select option in ddlstate i get corresponding cities , but when i again select a state , i get cities corresponding to present as well as previous state that i selected earlier.How should i solve this??
(i ve used database table to access cities corresponding to states using arraylist)
code behind for selected index changed---

void ddlstate_selectedindexchanged(object sender,event args e)
{
class1 c1=new class1(); //class1 contains method fillcity that has returns cities in arraylist

arraylist al=new arraylist();

al=null//initialising arraylist

al=c2.fillcity(ddl.selecteditem.text);//fillcity has input parameter as state which has tp be selected

for(int i=0;i<al.count;i++)
{
class2 c2=(class2)al;//class2 is anotehr class that has variables state and city defined

ddlcity.items.add(new listitem(c2.city,c2.city)
}

}
 
//You need to add this before your loop
ddlcity.items.Clear();


for(int i=0;i<al.count;i++)
{
class2 c2=(class2)al;//class2 is anotehr class that has variables state and city defined

ddlcity.items.add(new listitem(c2.city,c2.city)
}

}

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top