| | |
populate two dropdownlist
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
You need two database tables.
One to store the Country ID and Name
The second table to store the Country ID, State Name and State Capital. Simple one to many relationship. Each country has many states, but a state only has one capital.
Populate the first combo with the country, and the value member with the country id. The second combo will contain the state name, and you can place the capital in the value member. If you web site is doing more with the state information then you might want to place a state id in the states table, and use that as the valuemember so that you can pull additional information about the state.
In the demo, you will see the event on the second drop down selected index change uses the country id, and the state id to find the capital value to place into the Label.
--Jerry
One to store the Country ID and Name
The second table to store the Country ID, State Name and State Capital. Simple one to many relationship. Each country has many states, but a state only has one capital.
Populate the first combo with the country, and the value member with the country id. The second combo will contain the state name, and you can place the capital in the value member. If you web site is doing more with the state information then you might want to place a state id in the states table, and use that as the valuemember so that you can pull additional information about the state.
In the demo, you will see the event on the second drop down selected index change uses the country id, and the state id to find the capital value to place into the Label.
--Jerry
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
I think you are struggling with understanding the one to many relationship.
Lets say you have 2 countrys defined in your country_master table. #1=USA, #2=Canada
You can have all USA's states listed in the states table, and you can also have all of the states found in Canada in this very same table. Each row in the states table also has a Country ID column that allows the SQL server to only get the states for a specific Country ID.
Therefore a T-SQL statement of "select * from States where Country_id=1"
will only bring back the states that belong to the USA. If Country_ID were set to 2 in this query, then only Canada's states would be returned.
The purpose of the first drop-down is to get the CountryID that will be used in the query against the States table... As long as you issue the query statement with the "where country_id = nnn", the second dropdown will only contain the states related to that country id.
Hope this Helps,
Jerry
Lets say you have 2 countrys defined in your country_master table. #1=USA, #2=Canada
You can have all USA's states listed in the states table, and you can also have all of the states found in Canada in this very same table. Each row in the states table also has a Country ID column that allows the SQL server to only get the states for a specific Country ID.
Therefore a T-SQL statement of "select * from States where Country_id=1"
will only bring back the states that belong to the USA. If Country_ID were set to 2 in this query, then only Canada's states would be returned.
The purpose of the first drop-down is to get the CountryID that will be used in the query against the States table... As long as you issue the query statement with the "where country_id = nnn", the second dropdown will only contain the states related to that country id.
Hope this Helps,
Jerry
•
•
Join Date: Nov 2007
Posts: 40
Reputation:
Solved Threads: 0
hi jerry thanks for dropdownlist, but i got another problem regarding updatating a profile of a login member, i created a storedprocedure for login information just look at my codding
my problem is i want to update some of login member column but iam not able to update, i wrote some coding for that just go through that,
please sought out my problem
thank you
raghu
C# Syntax (Toggle Plain Text)
CREATE PROCEDURE sp_UserValidation ( @Username varchar(50), @UserPassword varchar(20) ) AS IF EXISTS (SELECT UserName FROM LogIn1 WHERE UserName=@Username and UserPassword=@UserPassword) BEGIN return 1 END ELSE BEGIN return 0 END create table login1(username varchar(50)constraint pkusername primary key,userpassword varchar(20) , youranswer varchar(40),username varchar(20), useraddress varchar(100),usercity varchar(20),userpostal int, userphone int,usermobile int,Email varchar(30),website varchar(30))
C# Syntax (Toggle Plain Text)
protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4"); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "Update login1001 Set name = @username1001, pwd = @userpassword1001 where username1001= @username1001"; cmd.CommandType = CommandType.Text; SqlParameter para2; SqlParameter para3; SqlParameter para4; SqlParameter para5; //SqlParameter para6; SqlParameter para7; SqlParameter para8; SqlParameter para9; para2 = cmd.@Parameters.AddWithValue("loginaddress", tb1.Text); para3 = cmd.@Parameters.AddWithValue("logincity", t6.Text); para4 = cmd.@Parameters.AddWithValue("loginpostalcode", t7.Text); para5 = cmd.@Parameters.AddWithValue("loginphone", t8.Text); //para6 = cmd.Parameters.AddWithValue("loginfax", t9.Text); para7 = cmd.@Parameters.AddWithValue("loginmobile", t10.Text); para8 = cmd.@Parameters.AddWithValue("loginemail", t11.Text); para9 = cmd.@Parameters.AddWithValue("loginwebsite", t12.Text); int intnum; con.Open(); intnum = cmd.ExecuteNonQuery(); if (intnum > 0) { Label2.Text = "updated successfully"; } else { Label2.Text = "updarted failed"; } con.Close();
thank you
raghu
Last edited by cscgal; Dec 6th, 2007 at 5:37 am. Reason: Added code tags
![]() |
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
| Thread Tools | Search this Thread |
.net 2007 access activedirectory algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion cryptographyc#winformsencryption csharp custom database datagrid datagridview dataset date datetime degrees development disabled displayingopenforms draganddrop drawing encryption enum eventcloseformc# excel file foreach form format forms ftp function gdi+ image index index-error input install java label list listbox listener listview load mandelbrot math mathematics mouseclick mysql operator path photoshop picturebox pixelinversion post prime programming radians regex remoting richtextbox security server setup sleep socket sql statistics stream string table text textbox thread time timer totaldays update user usercontrol validation visual visualstudio webbrowser windows winforms wpf xml






