如何在下拉列表中使用循环? [英] how to for loop using in drop down list?
本文介绍了如何在下拉列表中使用循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望下拉的相同细节可以重复20次...每次我写< select>标签代码...我从我的sql数据库中获取下拉列表数据...是否有可能代码for for循环..
请帮助我..
我的示例代码如下
i want same details of drop down can be repeted in 20 times... every time i am writing the <select> tag code... i am fetching dropdown list data from my sql database... Is there any possible to code in for loop..
Pls any one help me ..
My example code is below
<select size="1" name="block" id="block" tabindex="1">
<%
set rs1=Server.CreateObject("ADODB.Recordset")
sql="select distinct bl_cd,bk from sidhsc3 order by bk asc"
rs1.open sql, con,2,3
do while not rs1.eof
%>
<option value="<% =rs1("bk") %>"><% =rs1("bk") %></option>
<%
' if request.Form("hud")=rs1("bk")
rs1.movenext
loop
rs1.close
%>
</select>
推荐答案
我有一段时间没有触及旧的经典asp,但是这是你可以尝试的东西。
I have not touched the old classic asp for some time, but here is something you could try.
<%
'global variable to store the Select Markup Template
Dim strSelectMarkup=""
Sub WriteSelect(strNameId)
'check if Select Markup has been generated already, if it has use it
If Not strSelectMarkup="" Then
Response.Write(Replace(strSelectMarkup,"[SELECTNAMEID]","NameId"))
Exit Sub
End If
'generate Select Markup if it has not been created yet
set rs1=Server.CreateObject("ADODB.Recordset")
sql="select distinct bl_cd,bk from sidhsc3 order by bk asc"
rs1.open sql, con,2,3
strSelectMarkup &= "<select size='1' name='[SELECTNAMEID]' id='[SELECTNAMEID]' tabindex='1'>"
Dim strBK
do while not rs1.eof
strBK=rs1("bk")
strSelectMarkup &= "<option value='" & strBK & "'>" & strBK & "</option>"
rs1.movenext
loop
rs1.close
strSelectMarkup &= "</select>"
Response.Write(Replace(strSelectMarkup,"[SELECTNAMEID]","NameId"))
End Sub
'Write out the Select Markup a few times
For x = 0 To 20
Call WriteSelect("block" & x)
Next
%>
我无法测试它,所以不确定它是否有效,但上面的代码有希望给你一些关于如何解决问题的想法。
旁注:为什么经典的ASP?
I have not been able to test it, so not sure if it works, but the code above will hopefully give you some ideas on how to tackle your problem.
On a side note: Why classic ASP?
这篇关于如何在下拉列表中使用循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文