一个标准动态下拉列表函数

来源:互联网 发布:大数据分析有什么用 编辑:程序博客网 时间:2024/05/29 17:21
转自这里:http://topic.csdn.net/t/20060820/18/4962708.html
<%   '动态标准下拉列表函数   'Table 要查询的表名(必正确)   'ValueField 用于option的value字段名(必正确),可与TextField相同   'TextField 用于option显示文本的字段名(必正确),可与ValueField相同   'OrderStr 查询排序(可为0字符窜)   'whereStr 查询条件(可为0字符窜)   'CurrVlaue 当前可传的值(可为0字符窜)   '默认数据库连接对象为conn   Function getStandardSelect(Table, ValueField, TextField, WhereStr, OrderStr, CurrValue)   Dim gssSql, gssRs, gssStr, gssSlted, newValue   If len(Table) = 0 or len(ValueField) = 0 or len(TextField) = 0 Then   getStandardSelect="<option>参数不完整</option>"   Exit Function   End If   If len(CurrValue&"") = 0 Then currValue = ""   gssSql = "SELECT "&ValueField&", "&TextField&" FROM "&Table&" "   if len(whereStr&"")>=1 Then   gssSql = gssSql&"where "&whereStr&""   end if   If len(OrderStr) >= 1 Then   gssSql = gssSql&"ORDER BY "&OrderStr&""   End If   gssStr = ""   call OpenConn(dbConnStr)   set gssRs = dbconn.execute(gssSql)   If gssRs.Eof Then     gssStr = "<option value="""">无项目</option>"   Else   Do While Not gssRs.eof   gssSlted = ""   newValue = gssRs(ValueField)   If len(newValue&"") = 0 Then newValue = ""   If Cstr(Trim(CurrValue)) = Cstr(Trim(newValue)) Then gssSlted = " selected"   gssStr = gssStr&"<option value="""&Trim(gssRs(ValueField))&""""&gssSlted&">"&Trim(gssRs(TextField))&"</option>"&vbCrLf   If gssRs.Eof Then Exit Do   gssRs.MoveNext     Loop   End If   gssRs.close   set gssRs = nothing   getStandardSelect = gssStr   End Function   %>     <select name="">   <option>请选择</option>   <%=getStandardSelect(Table, ValueField, TextField, WhereStr, OrderStr, CurrValue)%>   </select>
原创粉丝点击