i want to populate both using stored procedure. city should be populated as soon as the form gets loaded and if we select any city then accordingly the state gets filtered in second dropdown list.....plzzz help i am new to .NET(c#)
create 2 stored procedure for filling the state and city
create procedure stp_fillState // To fill the state
AS
BEGIN
select state_name from table order by(state_name)
END
// to fill the city of the state which is selected
create procedure stp_fillCity(@state_name varchar(30)) AS BEGIN
select city_name from table where state_id=(select state_id from state_table where state_name=@state_name) order by(city_name)
END
your tables should be like this
state_table
col1 state_name col2 state_id(PK)
city_table
col1 city_name col 2 city_id(pk) col3 state_id(fk)
Mark as Answer If the Post Helped you..
Skype : sandeep.d.shenoy Gmail : sandeepdshenoy@gmail.com
Vishal Pande...
Member
64 Points
33 Posts
*URGENT* new to .NET......populate two drop down list using stored procedure
Mar 20, 2012 08:14 PM|LINK
i have 2 drop down lists...
1.) state
2.)city
i want to populate both using stored procedure. city should be populated as soon as the form gets loaded and if we select any city then accordingly the state gets filtered in second dropdown list.....plzzz help i am new to .NET(c#)
Vishal Pandey
+91 9795575171
sairam62.cse
Participant
989 Points
309 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 04:29 AM|LINK
Use Casecadding dropdown .For Binding data
s.sairam
nilsan
All-Star
16826 Points
3684 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 04:43 AM|LINK
http://lmgtfy.com/?q=asp.net+cascading+dropdown
Honnappa
Participant
1112 Points
534 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 05:48 AM|LINK
check this
http://forums.asp.net/t/1781062.aspx/1?pls+help+me+very+argent+
My Profile
Sandeep Shen...
Participant
1678 Points
492 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 05:53 AM|LINK
hi
create 2 stored procedure for filling the state and city
Skype : sandeep.d.shenoy
Gmail : sandeepdshenoy@gmail.com
Vishal Pande...
Member
64 Points
33 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 06:20 AM|LINK
thanx SANDEEP...can u help me with the C# code how to display them in drop down list.
REGARDS
Vishal Pandey
Vishal Pandey
+91 9795575171
Sandeep Shen...
Participant
1678 Points
492 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 06:35 AM|LINK
hi,
my current system doesnt have vs2008 or above , but i will try to write the code , please reply if it return some error.
page_load() { if(!IsPostBack) { SqlDataReader dr=fillState(); while(dr.Read()) { DropDownList1.Items.Add(dr.GetValue(0).ToString()); } } } public static SqlDataReader fillState() { cn.Open(); SqlCommand cmd=new SqlCommand("procedure name to fill state",cn); cmd.CommandType=CommandType.StoredProcedure; SqlDataReader dr=cmd.ExecuteReader(); return dr; } private DropDownList1_SelectedIndexChanged() { string state_name=DropDownList1.SelectedItem.ToString(); SqlDataReader dr=fillCity(state_name); while(dr.Read()) { DropDownList2.Items.Add(dr.GetValue(0).ToString()); } } public static fillCity(string state_name) { cn.Open() SqlCommand cmd=new SqlCommand("procedure to fill city",cn); cmd.CommandType=CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@State_name",state_name); SqlDataReader dr=cmd.ExecuteReader(); return dr; }Skype : sandeep.d.shenoy
Gmail : sandeepdshenoy@gmail.com
Vishal Pande...
Member
64 Points
33 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 06:41 AM|LINK
thanx sandeep..but cant it be done with SQLDATA adapter
Vishal Pandey
+91 9795575171
Sandeep Shen...
Participant
1678 Points
492 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 06:45 AM|LINK
well, it can be ..but i use this method...
Skype : sandeep.d.shenoy
Gmail : sandeepdshenoy@gmail.com
bhaskar.mule
Contributor
2264 Points
656 Posts
Re: *URGENT* new to .NET......populate two drop down list using stored procedure
Mar 21, 2012 06:46 AM|LINK
HI
I HOPE IT WILL HELP YOU
http://csharpektroncmssql.blogspot.com/2011/12/cascading-dropdownl-lists-in-aspnet.html
Site:Rare technical solutions