Dynamically add content to one Dropdownlist on the basis of selection of other Dropdownlist

function FillCity() { str = document.all["MyDropDownList"].value ; document.all["DropDownList"].length=0; soption = "Select City" st = new Option(soption,""); document.all["DropDownList"].add(st) for (i=1;i

Contributed by
Rating: 3 stars3 stars3 stars3 stars3 stars / 34
August 11, 2002
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Here is the code.

<script runat="server" >
public void Page_Load ( object sender, EventArgs e)
{
MyDropDownList.Attributes.Add("OnChange", "FillCity()") ;
MyDropDownList.Items.Add(new ListItem("Selecy Country", ""));
MyDropDownList.Items.Add(new ListItem("India", "IND"));
MyDropDownList.Items.Add(new ListItem("United Kingdom", "UK"));
MyDropDownList.Items.Add(new ListItem("United States", "US"));
MyDropDownList.Items.Add(new ListItem("France", "FR"));
MyDropDownList.Items.Add(new ListItem("Srilanka", "SR"));
DropDownList.Items.Add(new ListItem("Selecy City", ""));
String strString;
strString = "<script language='JavaScript' >"; 
strString += "JCountry = new Array(15);";
strString += "JCountry[1] = 'IND';";
strString += "JCountry[2] = 'IND';";
strString += "JCountry[3] = 'US';";
strString += "JCountry[4] = 'US';";
strString += "JCountry[5] = 'US';";
strString += "JCountry[6] = 'UK';";
strString += "JCountry[7] = 'UK';";
strString += "JCity = new Array(20);";
strString += "JCity[1] = 'Mumbai';";
strString += "JCity[2] = 'Pune';";
strString += "JCity[3] = 'New York';";
strString += "JCity[4] = 'Chicago';";
strString += "JCity[5] = 'Washignton';";
strString += "JCity[6] = 'London';";
strString += "JCity[7] = 'Leeds';";
strString += "<" + "/" + "script>";
Response.Write(strString);
}
public void alphaSubmit(object sender , EventArgs e)
{

}
</script>

<script language="JavaScript" >
function FillCity()
{
str = document.all["MyDropDownList"].value ;
document.all["DropDownList"].length=0;
soption = "Select City"
st = new Option(soption,"");
document.all["DropDownList"].add(st)
for (i=1;i<8;i++){
if (JCountry[i] == str){
soption = JCity[i];
st = new Option(soption,soption);
document.all["DropDownList"].add(st)
}

}

}
</script>

<H1>Combination OF C# and JavaScript </H1><br>
By Laxmikant Shrotri
<Form name="MyForm" runat="server">
<asp:Dropdownlist id="MyDropDownList" DataValueField = "CountryCode" DataTextField = "Country" runat="server" />
<asp:Dropdownlist id="DropDownList" DataValueField = "CountryCode" DataTextField = "Country" runat="server" /> 

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials