How to transfer an array of data (retrived from database at server side) to client side variables?
-
I have two list boxes. First list box is filled with some enteries from database. Now when user select one entry from first list box(client-side event) then second list box is filled with values based on that first selection. Second list box enteries are retrived from database(server side action). Guide me how to do this.
-
I have two list boxes. First list box is filled with some enteries from database. Now when user select one entry from first list box(client-side event) then second list box is filled with values based on that first selection. Second list box enteries are retrived from database(server side action). Guide me how to do this.
Simple solution is to use a postback in ASP.Net and then get the items for the other listbox Other solution is to create an asp.net page which generates XML. XML can be loaded by javascript at the client side. And then you can change the entries of the second box. A thing i have to warn you is that the Viewstate will not work because the items are not set runtime. But you can still use Page.Response["ddlName"] tot get the selected one. The last solution is very sexy i think. Maybe i will write my first article about this. :-D
-
Simple solution is to use a postback in ASP.Net and then get the items for the other listbox Other solution is to create an asp.net page which generates XML. XML can be loaded by javascript at the client side. And then you can change the entries of the second box. A thing i have to warn you is that the Viewstate will not work because the items are not set runtime. But you can still use Page.Response["ddlName"] tot get the selected one. The last solution is very sexy i think. Maybe i will write my first article about this. :-D
Thanks for ur reply. I want code for ASP 3.0 :-D
-
Thanks for ur reply. I want code for ASP 3.0 :-D
mkashifkkj wrote: I want code for ASP 3.0 I have the code of it... but its flavoured with Java Script too... interested?? I was born intelligent
Education ruined me!. -
mkashifkkj wrote: I want code for ASP 3.0 I have the code of it... but its flavoured with Java Script too... interested?? I was born intelligent
Education ruined me!.yes send it
-
yes send it
The following is the code for the dropdownlist... written in ASP to pump the html code. The first drop down is for the CITY, and the other for the CATEGOREY.
<% Response.Write "" Response.Write "Select City" for ii=1 to temp_rs.RecordCount if (Request ("srchCat") = temp_rs ("City")) then selOpt = "selected" else selOpt = "" end if Response.Write "" & temp_rs ("City") & "" temp_rs.MoveNext next Response.Write "" Response.Write "" Response.Write "Select Category" Response.Write "" %>
The following is the JSCRIPT and ASP combined stuff......<!-- var groups = document.drsrchform.City.options.length var group = new Array(groups) // alert ("Hai"); for (i=0; i<groups; i++) group[i]=new Array() <% Dim curVal, cityCnt, catCnt, curCity cityCnt = 1 catCnt = 0 set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;" & "Data Source=" &Server.MapPath(drDatabase) Set temp_rs = Server.CreateObject("ADODB.RecordSet") SqlStr= "SELECT distinct Category, City FROM DocDetails where Country='XXX' order by City" temp_rs.Open SqlStr, conn, 1,3 curCity = temp_rs ("City") Do While not temp_rs.EOF curVal = temp_rs ("Category") if (curCity <> temp_rs("City")) then cityCnt = cityCnt + 1 catCnt = 0 curCity = temp_rs ("City") end if %> // alert ("<%=curVal%>" + " <%=cityCnt%>" + " <%=catCnt%>"); group[<%=cityCnt%>][<%=catCnt%>] = new Option ("<%=curVal%>","<%=curVal%>"); <% catCnt = catCnt + 1 temp_rs.MoveNext loop set temp_rs=nothing set Conn=nothing %> var temp=document.drsrchform.Category function redirect(x) { for (m=temp.options.length-1;m>0;m--) temp.options[m]=null for (i=0;i<group[x].length;i++) { temp.options[i]=new Option(group[x][i].text,group[x][i].value) } temp.options[0].selected=true } //-->
Please notice that... if there is ANY change in the name of the vars/anything... this wont wont work. Hav