<AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)> _
Public Function HandleSelect(ByVal table As String, ByVal eventSource As String, ByVal filterValue As String, ByVal targetControl As String) As StreetNameResponse
Dim tName As TableName
Dim filter As String = Nothing
Dim sort As String = Nothing
Dim textField As String = Nothing
Dim valueField As String = Nothing
Dim name As String = Nothing
Dim onChange As String = Nothing
'Assign security filter
CheckSecurityFilter()
Select Case table.ToLower
Case "county"
tName = TableName.County
If filterValue = "-1" Or filterValue = "" Then
If _restrictionLevel = RestrictionLevel.District Then
filter = _restrictionFilter
End If
Else
filter = String.Format("maintdisnmbr in ({}0)", filterValue)
End If
tName = TableName.County
sort = "countyname ASC"
textField = "countyname"
valueField = "countynmbr"
name = "selCounty"
onChange = "CheckSubmitEnabled();ajaxGetSelect('city','county', this, 'spanCity')"
Case "city"
If filterValue = "-1" Or filterValue = "" Then
'No value selected, set the filter to the default security value
If _restrictionLevel = RestrictionLevel.District Or _restrictionLevel = RestrictionLevel.County Then
filter = _restrictionFilter
End If
Else
Select Case eventSource.ToLower
Case "district"
filter = String.Format("maintdisnmbr in ({0})", filterValue)
Case "county"
filter = String.Format("countynmbr in ({0})", filterValue)
End Select
End If
tName = TableName.MasterCity
sort = "sams_cityname ASC"
textField = "sams_cityname"
valueField = "cityname_value"
name = "selCity"
onChange = "CheckSubmitEnabled()"
End Select
Dim selOutput As HtmlSelect = BuildSelect(tName, filter, sort, textField, valueField, name, onChange)
Dim outControl As New StreetNameResponse
outControl.targetControl = targetControl
outControl.outputControl = selOutput
MyBase.ProperCaseSelectControl(selOutput)
Return outControl
End Function
在上面的代码中,我遇到了调试问题。关键在于HTML我有三个选择标签。区,县,市。如果您选择一个区域,它应该更新县和城市以仅限制该区域中的县或城市。城市运作完美但县没有。我发现当运行上面的代码时,如果它运行通过County Case段,它只会停止filter = String.Format(“maintdisnmbr in({} 0)”,filterValue)。如果我逐步执行代码,则代码无法完成。如果我不一步一步地向前跳,它会给我一个错误,说输入字符串没有格式化。这不是我的代码,我没有使用Ajax,但我必须解决它,请帮助至少弄清楚问题会很棒。
答案 0 :(得分:1)
此:
“maintdisnmbr in({} 0)”
应该是这样的:
“maintdisnmbr in({0})”
但如果你想要容易受到sql注入攻击。如果你想要好的代码,你将阅读关于正确地将列表传递给sql server的这一系列文章: