| | |
on selecting country from one dropdownlist ...states of selected country is not getti
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 0
on selecting country from one dropdownlist ...states of selected country is not getti
0
#1 Dec 9th, 2008
pls give me the complete code for it ..i tryed but not getting the output..pls help..iam pasting the code here but no output
my database is something like this...i have two tables countryname(countryid identity(1,1),countryname) and statename(stateid identity(100,1),statename,countryid)
so i have inserted 78 countries in country table in tat 73rd is india...
n i have inserted states of india in statename table(28)..how to get india's states wen india in selected
aspnet Syntax (Toggle Plain Text)
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["con"].ToString()); protected void Page_Load(object sender, EventArgs e) { Response.Write("sql is connected"); SqlDataAdapter da = new SqlDataAdapter("select countryid,countryname from countryname", cn); DataSet ds = new DataSet(); da.Fill(ds,"countryname"); ddlcountryname.DataSource = ds.Tables["countryname"]; ddlcountryname.DataTextField = "countryname"; ddlcountryname.DataValueField = "countryid"; ddlcountryname.DataBind(); } protected void ddlcountryname_SelectedIndexChanged(object sender, EventArgs e) { string country_id; country_id = ddlcountryname.SelectedValue.ToString(); SqlDataAdapter da1=new SqlDataAdapter("select stateid,statename from statename where countryid=' country_id'",cn); DataSet ds1 = new DataSet(); da1.Fill(ds1, "statename"); ddlstatename.DataSource = ds1.Tables["statename"]; ddlstatename.DataTextField = "statename"; ddlstatename.DataValueField = "stateid"; ddlstatename.DataBind(); }
so i have inserted 78 countries in country table in tat 73rd is india...
n i have inserted states of india in statename table(28)..how to get india's states wen india in selected
Last edited by cscgal; Dec 9th, 2008 at 1:16 pm. Reason: Added code tags
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#2 Dec 9th, 2008
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#3 Dec 10th, 2008
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 0
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#4 Dec 10th, 2008
if i keep autopostback to tru ...if i select some country say america...iam getting the first country selected ..tat is afganisthan....
i have
afganisthan
america
india
say if i select india afganisthan is only coming.....n i want databasee like how to insert states for country india....like i said i have 3 fields...but i have 28 states....how to write table...
lot of confusion
i have
afganisthan
america
india
say if i select india afganisthan is only coming.....n i want databasee like how to insert states for country india....like i said i have 3 fields...but i have 28 states....how to write table...
lot of confusion
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#5 Dec 10th, 2008
hi,
inoder to get states its compulsory that u set autopostback to true.The Reply u gave is confusing to me.
can u be eloborate .
coming to creating table
table1
countryid
country name
table 2
id
country_id
state_id
state_name
when u select a country
the query for u r state would be
select state_id,state_name from table2 where country_id="+int.parse(ddlcountry.selectedvalue)+"
inoder to get states its compulsory that u set autopostback to true.The Reply u gave is confusing to me.
can u be eloborate .
coming to creating table
table1
countryid
country name
table 2
id
country_id
state_id
state_name
when u select a country
the query for u r state would be
select state_id,state_name from table2 where country_id="+int.parse(ddlcountry.selectedvalue)+"
If u r query is achieved,mark the thread as solved
Live and Let Live
Live and Let Live
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 0
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#6 Dec 10th, 2008
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 0
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#7 Dec 10th, 2008
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#8 Dec 10th, 2008
SqlDataAdapter da1=new SqlDataAdapter("select stateid,statename from statename where countryid=' country_id'",cn); Try and fix this line cos you dont need to put the country_id within single and Double qoutations marks which u have declared and set its value to the one selected on DDL
The better sollution will be
SqlDataAdapter da1=new SqlDataAdapter("select stateid,statename from statename where countryid = " + country_id ,cn); Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#9 Dec 10th, 2008
Re: on selecting country from one dropdownlist ...states of selected country is not getti
0
#10 Dec 10th, 2008
Hi
did you tried doing this.. ?
I think this is the only thing u are missing...
bocz after the country is selected the page gets PostBack to server
and execute the Page_Load everytime.. that's the reason u are getting "Afghanistan" selected even after selecting "America" as it is getting bind everytime
did you tried doing this.. ?
asp.net Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { if(!IsPostback) { // your complete Country code here } }
I think this is the only thing u are missing...
bocz after the country is selected the page gets PostBack to server
and execute the Page_Load everytime.. that's the reason u are getting "Afghanistan" selected even after selecting "America" as it is getting bind everytime
Last edited by peter_budo; Dec 12th, 2008 at 6:56 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Njoy koding... >>>
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Mac Address in ASP.net using vb.net / Ajax
- Next Thread: Hiding Columns in the datagrid
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox child class compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form gridview gudi iis image javascript list listbox menu mouse mssql nameisnotdeclared news novell numerical opera order parent problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security select serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview typeof validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xsl





