Asp > Miscellaneous
Display States according to Country selection...
Display States according to Country selection... ------we should have two tables in sql------- table: tblcountry create table tblcountry ( countryid varchar(20) primary key, country varchar(20) ) insert into tblcountry values('1','Canada') insert into tblcountry values('2','USA') insert into tblcountry values('3','Nepal') table: tblState create table tblstate ( stateid varchar(20) primary key, state varchar(20), countryid varchar(20) foreign key references tblcountry(countryid) ) insert into tblstate values('1','Alaska','2') insert into tblstate values('2','Puerto Rico','2') insert into tblstate values('3','Saint Thomas','2') --------------run above codes on sql------------- -------------------------------------------------------> <% ConnString="Provider=SQLOLEDB.1;Persist Security Info=False;" ConnString=ConnString & "User ID=sa;Initial Catalog=master;" ConnString=ConnString & "Data Source=computername" 'give your computer name instead of computername 'on "Data Source=computername" on above string Set Conn=server.createobject("ADODB.Connection") Conn.open ConnString Set rs=Server.CreateObject("ADODB.RECORDSET") rs.Open "select * from tblstate",Conn,3 Response.write "" strSQL="select * from tblcountry order by country" rs.Open strSQL,Conn StrCountry=rs("countryid") Set rsstate=server.createobject("ADODB.RECORDSET") rsstate.CursorLocation=adUseClient strSQL="select * from tblstate where countryid='" & StrCountry & "'" rsstate.Open strSQL,Conn %>
Country
---------- Select Country --------
<% For i=1 to rs.RecordCount %>
" <%if cint(rs("countryid"))=cint(StrCountry) then%>Selected<%End if%>> <%=rs.Fields("country")%>
<%rs.MoveNext Next rs.Close %>
State/Province
<%if rsstate.RecordCount<>0 then%> <%Do while not rsstate.EOF%>
"><%=rsstate("state")%>
<%rsstate.movenext loop else %>
------- County/State N/A -------
<%end if%>
<% rsstate.close Set RsState=nothing Conn.close Set Conn=nothing %>
Asp Codes
ActiveX
ADO
Array
Code Snippets
Components
Data Access
Date Time
Files
Graphics
HTML Formatting
Mathematics
Miscellaneous
Sessions
SQL
Strings
Techniques
XML