从下拉列表ASP排除某些选项 [英] Exclude certain selections from a drop down list ASP
问题描述
我工作的一个ASP(内支付网关)。在被从数据库中拉在下拉菜单中的选项。我不能碰的数据库,所以不得不从code攻击问题。
下面是我需要排除的值名称 _01BM(Q)
下面是code为下拉。
<选择名称=programgroup的onchange =onProgramGroup()>
<%调用buildDropDownList(strProgramGroup code,rsProgramGroup,ProgramGroup code,ProgramGroupDescription,FALSE)%GT;
< /选择>
我真的AP preciate对这个家伙的任何帮助。
下面是code的方法:
子buildDropDownList(strCurrentSelection,objListData,STR codeNAME,strDescriptionName,blnIncludeOther)
如果不objListData.BOF然后
objListData.MoveFirst
万一
虽然没有objListData.EOF
的Response.Write<期权价值='&放大器; objListData(STR codeNAME)及'
如果STRCOMP(strCurrentSelection,objListData(STR codeNAME),1)= 0,则
的Response.Write入选
万一
回复于>中&安培; objListData(strDescriptionName)及< /选项>中&安培; VbCrLf
objListData.MoveNext
WEND 如果blnIncludeOther然后
的Response.Write<期权价值='<其它>'
如果strCurrentSelection<> 和INSTR(1,<其它>中,strCurrentSelection)= 1,则
的Response.Write入选
万一
的Response.Write>其他< /选项>中&安培; VbCrLf
万一
结束小组
您将不得不改变方法建立下拉。既然你没有为我们提供了code吧,我给你一个骨架,可以用它来改变你的实际code。
为了使它更通用和更少的丑陋,更好地传递值(S)排除的方法,为一个数组,而不是硬在那里它们编码。
因此,该方法应该是这样的:
子buildDropDownList(strProgramGroup code,rsProgramGroup,someParamHere,anotherParam,boolParam,arrValuesToExclude)
暗淡excludedValuesMapping,X
设置excludedValuesMapping =的Server.CreateObject(的Scripting.Dictionary)
对于x = 0到UBound函数(arrValuesToExclude)
excludedValuesMapping.Add(LCASE(arrValuesToExclude(X)),真)
下一个 ......不明code这里... 做,直到rsProgramGroup.EOF
strCurrentValue = rsProgramGroup(valueFieldName)
如果excludedValuesMapping.Exists(LCASE(strCurrentValue))然后
值应被排除在外,你可以在这里做的东西,但它写到浏览器
其他
strCurrentText = rsProgramGroup(textFieldName)
的Response.Write(<期权价值=和替换(strCurrentValue,,,&放大器; QUOT;)及>中和放大器; strCurrentText&安培;< /选项> )
万一
rsProgramGroup.MoveNext
循环
结束小组
和使用它:
<%调用buildDropDownList(strProgramGroup code,rsProgramGroup,ProgramGroup code,ProgramGroupDescription,假,阵列(_ 01BM(Q))) %GT;
现在让您的code,如果你不想让通用的,你也可以通过在 buildDropDownList $ C $有这样code忽略特定值C>子:
昏暗当前codeValue
虽然没有objListData.EOF
当前codeValue = objListData(STR codeNAME)
如果(用Ucase(当前codeValue)LT;>_ 04GIDBM)和_
(用Ucase(当前codeValue)LT;>_ 05GIDFM)和_
(用Ucase(当前codeValue)LT;>_ 08EXHRM)和_
(用Ucase(当前codeValue)LT;>_ 10EXMKT)和_
(用Ucase(当前codeValue)LT;>_ 12EXTTH)和_
(用Ucase(当前codeValue)LT;>_ 17EXHSC),然后
的Response.Write<期权价值='&放大器;当前codeValue&安培; '
如果STRCOMP(strCurrentSelection,目前codeValue,1)= 0,则
的Response.Write入选
万一
回复于>中&安培; objListData(strDescriptionName)及< /选项>中&安培; VbCrLf
万一
objListData.MoveNext
WEND
这将跳过此类值的任何记录,而不会输出一个下拉选择他们。
I'm working on a ASP (Within the payment gateway). The options in the drop down at being pulling in from a database. I can't touch the database so have to attack the matter from the code.
Here is the value name that I need to exclude _01BM(Q)
Here is the code for the drop down.
<select name="programgroup" onchange="onProgramGroup()">
<% Call buildDropDownList(strProgramGroupCode, rsProgramGroup, "ProgramGroupCode", "ProgramGroupDescription", False)%>
</select>
I would really appreciate any help on this guys.
Here is the code for the method:
Sub buildDropDownList(strCurrentSelection, objListData, strCodeName, strDescriptionName, blnIncludeOther)
If Not objListData.BOF Then
objListData.MoveFirst
End If
While Not objListData.EOF
Response.Write "<option value='" & objListData(strCodeName) & "' "
If StrComp(strCurrentSelection, objListData(strCodeName),1) = 0 then
Response.Write "selected"
End If
Response.Write ">" & objListData(strDescriptionName) & "</option>" & VbCrLf
objListData.MoveNext
Wend
if blnIncludeOther then
Response.Write "<option value='<Other>' "
If strCurrentSelection <> "" and InStr(1, "<Other>", strCurrentSelection) = 1 then
Response.Write "selected"
End If
Response.Write ">Other</option>" & VbCrLf
end if
End Sub
You will have to change the method building the drop down. Since you did not provide us with the code for it, I'll give you a skeleton, and can use it to change your actual code.
To make it more generic and less ugly, better pass the value(s) to exclude to the method, as an array, instead of hard coding them in there.
So, the method should look like this:
Sub buildDropDownList(strProgramGroupCode, rsProgramGroup, someParamHere, anotherParam, boolParam, arrValuesToExclude)
Dim excludedValuesMapping, x
Set excludedValuesMapping = Server.CreateObject("Scripting.Dictionary")
For x=0 To UBound(arrValuesToExclude)
excludedValuesMapping.Add(LCase(arrValuesToExclude(x)), True)
Next
'...unknown code here...
Do Until rsProgramGroup.EOF
strCurrentValue = rsProgramGroup(valueFieldName)
If excludedValuesMapping.Exists(LCase(strCurrentValue)) Then
'value should be excluded, you can do something here, but not write it to browser
Else
strCurrentText = rsProgramGroup(textFieldName)
Response.Write("<option value=""" & Replace(strCurrentValue, """", """) & """>" & strCurrentText & "</option>")
End If
rsProgramGroup.MoveNext
Loop
End Sub
And to use it:
<% Call buildDropDownList(strProgramGroupCode, rsProgramGroup, "ProgramGroupCode", "ProgramGroupDescription", False, Array("_01BM(Q)"))%>
Now having your code, and if you don't want to make it generic, you can also ignore specific values by having such code in the buildDropDownList
sub:
Dim currentCodeValue
While Not objListData.EOF
currentCodeValue = objListData(strCodeName)
If (UCase(currentCodeValue)<>"_04GIDBM") And _
(UCase(currentCodeValue)<>"_05GIDFM") And _
(UCase(currentCodeValue)<>"_08EXHRM") And _
(UCase(currentCodeValue)<>"_10EXMKT") And _
(UCase(currentCodeValue)<>"_12EXTTH") And _
(UCase(currentCodeValue)<>"_17EXHSC") Then
Response.Write "<option value='" & currentCodeValue & "' "
If StrComp(strCurrentSelection, currentCodeValue, 1) = 0 then
Response.Write "selected"
End If
Response.Write ">" & objListData(strDescriptionName) & "</option>" & VbCrLf
End If
objListData.MoveNext
Wend
This will just skip any records with such values, and will not output a drop down option for them.
这篇关于从下拉列表ASP排除某些选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!