ASP 下拉菜单设置数据库中的值
在ASP修改页面有下拉菜单、点击修改页面下拉菜单值变为默认值、现在需要设置成原来是什么值、点修改后还是那个值。FunctiongetList(i,sTable,iId,s...
在ASP修改页面有下拉菜单、点击修改页面下拉菜单值变为默认值、现在需要设置成原来是什么值、点修改后还是那个值。
Function getList(i,sTable,iId,sValue,sName,selfValue)
If i < 1 Or i > 2 Then
getList = ""
Exit Function
End If
Dim strList
Dim rs
If i = 1 Then
strList = "<select name=""" & sName & """ selfValue=""" & selfValue & """>"
strList = strList & "<option value="""">"&Selects&"</option>"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * From [" & sTable & "]",conn,3,1
Do While Not rs.BOF And Not rs.EOF
strList = strList & "<option value=""" & rs(sValue) & """>" & rs(sValue) & "</option>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
strList = strList & "</select>"
getList = strList
Else
strList = "<select name=""" & sName & """ selfValue=""" & selfValue & """>"
strList = strList & "<option value="""">"&Selects&"</option>"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * From [" & sTable & "]",conn,3,1
Do While Not rs.BOF And Not rs.EOF
strList = strList & "<option value=""" & rs(iId) & """>" & rs(sValue) & "</option>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
strList = strList & "</select>"
getList = strList
End If
End Function
<% = getList(1,"zhiwei","","zhiwei","zhiwei",""&viewzhiwei&"") %>
简单点说就是实现下拉菜单,如何在进入编辑页面时下拉菜单显示的是数据库中的值 展开
Function getList(i,sTable,iId,sValue,sName,selfValue)
If i < 1 Or i > 2 Then
getList = ""
Exit Function
End If
Dim strList
Dim rs
If i = 1 Then
strList = "<select name=""" & sName & """ selfValue=""" & selfValue & """>"
strList = strList & "<option value="""">"&Selects&"</option>"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * From [" & sTable & "]",conn,3,1
Do While Not rs.BOF And Not rs.EOF
strList = strList & "<option value=""" & rs(sValue) & """>" & rs(sValue) & "</option>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
strList = strList & "</select>"
getList = strList
Else
strList = "<select name=""" & sName & """ selfValue=""" & selfValue & """>"
strList = strList & "<option value="""">"&Selects&"</option>"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * From [" & sTable & "]",conn,3,1
Do While Not rs.BOF And Not rs.EOF
strList = strList & "<option value=""" & rs(iId) & """>" & rs(sValue) & "</option>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
strList = strList & "</select>"
getList = strList
End If
End Function
<% = getList(1,"zhiwei","","zhiwei","zhiwei",""&viewzhiwei&"") %>
简单点说就是实现下拉菜单,如何在进入编辑页面时下拉菜单显示的是数据库中的值 展开
展开全部
Do While Not rs.BOF And Not rs.EOF
strList = strList & "<option value=""" & rs(sValue) & """>" & rs(sValue) & "</option>" '改造一下这句就可以,修改如下:
strList = strList & "<option value=' & rs(sValue) &"'"
if rs(sVAlue)="此处为<select>的默认值(即你说的数据库中的值" then strList = strList & " selected >" else strList = strList & ">" '在<option>中加一个selected表示该选线被选中
下面还有一句,类似。有问题可以百度HI我。
strList = strList & "<option value=""" & rs(sValue) & """>" & rs(sValue) & "</option>" '改造一下这句就可以,修改如下:
strList = strList & "<option value=' & rs(sValue) &"'"
if rs(sVAlue)="此处为<select>的默认值(即你说的数据库中的值" then strList = strList & " selected >" else strList = strList & ">" '在<option>中加一个selected表示该选线被选中
下面还有一句,类似。有问题可以百度HI我。
追问
非常感谢的你回答、但是一共有4个下拉菜单、
...........
对应的数据字段为leibie1.......leibe4
能不能给个示范代码、谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询