943,914 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 2372
  • ASP.NET RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 10th, 2008
0

Re: on selecting country from one dropdownlist ...states of selected country is not getti

thanks a lot...vizy,greeny n traicey..u made it ..thanks a ton..n thanks for replying for my so called questions
Reputation Points: 7
Solved Threads: 0
Newbie Poster
divyasrinivasan is offline Offline
21 posts
since Dec 2008
Dec 11th, 2008
0

Re: on selecting country from one dropdownlist ...states of selected country is not getti

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
asp.net Syntax (Toggle Plain Text)
  1. SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["con"].ToString());
  2.  
  3. protected void Page_Load(object sender, EventArgs e)
  4. {
  5.  
  6.  
  7. Response.Write("sql is connected");
  8. SqlDataAdapter da = new SqlDataAdapter("select countryid,countryname from countryname", cn);
  9. DataSet ds = new DataSet();
  10. da.Fill(ds,"countryname");
  11. ddlcountryname.DataSource = ds.Tables["countryname"];
  12. ddlcountryname.DataTextField = "countryname";
  13. ddlcountryname.DataValueField = "countryid";
  14. ddlcountryname.DataBind();
  15.  
  16.  
  17. }
  18. protected void ddlcountryname_SelectedIndexChanged(object sender, EventArgs e)
  19. {
  20. string country_id;
  21. country_id = ddlcountryname.SelectedValue.ToString();
  22. SqlDataAdapter da1=new SqlDataAdapter("select stateid,statename from statename where countryid=' country_id'",cn);
  23. DataSet ds1 = new DataSet();
  24. da1.Fill(ds1, "statename");
  25. ddlstatename.DataSource = ds1.Tables["statename"];
  26. ddlstatename.DataTextField = "statename";
  27. ddlstatename.DataValueField = "stateid";
  28. ddlstatename.DataBind();
  29. }
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


I did a similar one But now sure whether this helps you.

I created a table like


tblState has:
1)State_Id(int 4,Identity Increment by 1)
2)CountryName(char 50 Allow Nulls)

3)State_Name(char 50 Allow Nulls)

The code I has is in classic asp.I am posting just to give an idea for you.Hope this helps you.

asp.net Syntax (Toggle Plain Text)
  1. Set Conn = Server.CreateObject("ADODB.Connection")
  2. connStr = "Provider=; Driver={SQL Server}; Server=sample; Database=data; DSN=login; UID=vari; PWD=ullet;"
  3. Conn.Open(connStr)
  4.  
  5. sql = ""
  6. sql = "select * from tblState"
  7. Set RS = Conn.Execute(sql)
  8. If RS.BOF And RS.EOF Then
  9. Error_Msg = "Database Connection Failed. Please contact the systems administrator."
  10. Else
  11. do until RS.EOF
  12. region = RS.Fields("CountryName")
  13. commid = cdbl(RS.Fields("State_Id"))
  14. comm = RS.Fields("State_Name")
  15.  
  16. if region = region_form then
  17. comm_options = comm_options & "<option value=" & commid & " selected>" & trim(comm) & "</option>"
  18. else
  19. comm_options = comm_options & "<option value=" & commid & ">" & trim(comm) & "</option>"
  20. end if
  21. RS.movenext
  22. loop
  23. End If

If you need more briefly let me know i can help you

terry
Last edited by peter_budo; Dec 12th, 2008 at 6:57 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
terrible is offline Offline
2 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Mac Address in ASP.net using vb.net / Ajax
Next Thread in ASP.NET Forum Timeline: Hiding Columns in the datagrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC