| | |
populate two dropdownlist
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
Simply write an event handler on the SelectedIndex change of the combobox to adjust the item for the second. On the second, have another event handler that sets the textbox value. You can populate a Combo using objects that contain the matching information to go into the text box.
Is this a homework assignment ?
Is this a homework assignment ?
•
•
Join Date: Nov 2007
Posts: 40
Reputation:
Solved Threads: 0
thank you or ypur advice
but i am developing web application using C#,just look at my code which is giving error message...
If i want to select any country from 1st dropdownlist then,2nd dropdownlist should populate with all the state of that paticular country only and if we select any state from 2nd dropdown then the capital should be placed in text box beside that and so on...
but i am developing web application using C#,just look at my code which is giving error message...
C# Syntax (Toggle Plain Text)
if (Page.IsPostBack == false) { SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4"); SqlDataAdapter da = new SqlDataAdapter("select countyr_id,countryname from country_master", con); DataSet ds1 = new DataSet(); da.Fill(ds1, "country_master"); dd1.DataSource = ds1.Tables["country_master"]; dd1.DataTextField = "countryname"; dd1.DataValueField = "countyr_id"; dd1.DataBind(); } } protected void dd1_SelectedIndexChanged(object sender, EventArgs e) { string countryid; countryid = dd1.SelectedValue; SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4"); SqlDataAdapter da1 = new SqlDataAdapter("SELECT stateid,statename FROM countrystate"); DataSet ds1 = new DataSet(); da1.Fill(ds1, "countrystate"); dd2.DataSource = ds1.Tables["countrystate"]; dd2.DataTextField = "statename"; dd2.DataValueField = "stateid"; dd2.DataBind(); } protected void dd2_SelectedIndexChanged(object sender, EventArgs e) { string stateid; stateid = dd2.SelectedValue; }
Last edited by cscgal; Dec 4th, 2007 at 3:07 am. Reason: Added code tags
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
You need to specify what country to use when you pull the data for the second drop down.
This way it will only contain the states for that country.
C# Syntax (Toggle Plain Text)
string sql = "SELECT stateid,statename FROM countrystate where country_id='{0}' "; SqlDataAdapter da1 = new SqlDataAdapter( string.Format(sql,countryid) );
This way it will only contain the states for that country.
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
Your code should work fine as is, you just need to give the Where Country_id= ... in the query so that it returns the states for that country.
C# Syntax (Toggle Plain Text)
protected void dd1_SelectedIndexChanged(object sender, EventArgs e) { string countryid; countryid = dd1.SelectedValue; SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4"); SqlDataAdapter da1 = new SqlDataAdapter(string.Format("SELECT stateid,statename FROM countrystate where country_id='{0}' ",countryid) ); DataSet ds1 = new DataSet(); da1.Fill(ds1, "countrystate"); dd2.DataSource = ds1.Tables["countrystate"]; dd2.DataTextField = "statename"; dd2.DataValueField = "stateid"; dd2.DataBind(); }
![]() |
Similar Threads
- SelectedIndexChanged in DropDownList won't trigger (VB.NET)
- asynchronous dropdownlist any idea (ASP.NET)
- Dropdownlist.... please help (C#)
- dropdownlist not firing (VB.NET)
- dropdownlist not firing (ASP.NET)
- please anybody to help Dropdownlist selected index problem (ASP.NET)
- POpulate DataGrid (VB.NET)
- retrieving ids from dynamically created controls in asp.net (ASP)
- DataGrid: Edit mode, the index of a dropdownlist does not start at the right Value (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Highlight the data in the DataGrid when it is searched...
- Next Thread: need help for distributed Application
Views: 12424 | Replies: 29
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button buttons c# chat check checkbox class client code combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ http httpwebrequest image index input install label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming regex remote remoting resource richtextbox saving serialization server sleep socket sql statistics stream string tcp text textbox time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





