我有一个 if 语句,需要检查传递的控件是复选框还是单选按钮
If TypeOf (Control) Is CheckBox Then
If count = 1 Then
text += Me.GetCheckBoxValueJQuerySyntax(Control.ClientID) & " + '~' + "
Else
text += Me.GetCheckBoxValueJQuerySyntax(Control.ClientID) & "'~' + "
End If
End If
If TypeOf (Control) Is RadioButton Then
If CType(Control, RadioButton).GroupName <> "" Then
If Not Me._GroupNameArrayList.Contains(CType(Control, RadioButton).GroupName) Then
Me._GroupNameArrayList.Add(CType(Control, RadioButton).GroupName)
If count = 1 Then
text += Me.GetRadioValueJQuerySyntax(Control.ClientID) & " + '~' + "
Else
text += Me.GetRadioValueJQuerySyntax(Control.ClientID) & "'~' + "
End If
End If
Else
If count = 1 Then
text += Me.GetRadioValueJQuerySyntax(Control.ClientID) & " + '~' + "
Else
text += Me.GetRadioValueJQuerySyntax(Control.ClientID) & "'~' + "
End If
End If
End If
这会失败,因为复选框和重播按钮派生自同一类,所以我如何检查控件是复选框还是单选按钮
最佳答案
你已经很接近了; RadioButton
派生自 CheckBox
,因此从技术上讲,它们都是 CheckBox
。因此,在这种情况下,您可以翻转语句并使用 Else If
来获取您要查找的结果。
If TypeOf Control Is RadioButton Then
' The control is a RadioButton.
ElseIf TypeOf Control Is CheckBox Then
' The control is a CheckBox.
End If
关于asp.net - 如何判断一个控件是复选框还是单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8436137/