我希望仅在选择单选按钮时才会显示文本框。我尝试使用RadioButtonList,但我无法让它工作,所以我使用单独的单选按钮。 然而,它无效。以下是代码:
Protected Sub radItem_CheckedChanged(sender As Object, e As EventArgs) Handles radItem.CheckedChanged
If radItem.Checked = True Then
radClient.Checked = False
radUser.Text = False
btnSearch.Visible() = True
txtSearch.Visible() = True
End If
End Sub
Protected Sub radUser_CheckedChanged(sender As Object, e As EventArgs) Handles radUser.CheckedChanged
If radUser.Checked = True Then
radItem.Checked = False
radClient.Text = False
btnSearch.Visible() = True
txtSearch.Visible() = True
End If
End Sub
Protected Sub radClient_CheckedChanged(sender As Object, e As EventArgs) Handles radClient.CheckedChanged
If radClient.Checked = True Then
radItem.Checked = False
radUser.Text = False
btnSearch.Visible() = True
txtSearch.Visible() = True
End If
End Sub
我很确定无论如何都有一种非常有效的方法。
答案 0 :(得分:0)
正如提到的tymeJV,请移除()
Visible()
此外,您不需要禁用其他radioButtons,除非它们是专门分组的。
由于无论选择哪个单选按钮,您始终都可以看到按钮/文本框,因此您无需检查单选按钮值。你的活动应该是这样的(改变其他人跟随诉讼)
Protected Sub radItem_CheckedChanged(sender As Object, e As EventArgs) Handles radItem.CheckedChanged
btnSearch.Visible = True
txtSearch.Visible = True
End Sub
答案 1 :(得分:0)
您应该使用Click事件,因为您正在处理相同的多个单选按钮
Protected Sub rad_Click(sender As Object, e As EventArgs) Handles radItem.Click, radUser.Click, radClient.Click
If Ctype(sender, RadioButton).Checked = False Then Exit Sub
Select Case Ctype(sender, RadioButton).Name
Case "radItem"
radUser.Text = False 'You are setting the Text value to False?
'Are you sure about this?
Case "radUser"
radClient.Text = False
Case Else 'radClient
radUser.Text = False
End Select
'You are doing this regardless of which radio button is checked
radItem.Checked = False 'This is weird. You wont be able to use radItem.
'I dont think you need this two lines anymore. There is always 1 RadioButton that is checked
btnSearch.Visible = True
txtSearch.Visible = True
End Sub
答案 2 :(得分:0)
票价,在将“GroupName”属性添加到单选按钮后,您无需设置其他无线电的文本或已检查状态,它将自动更新。
对于显示/隐藏文本框,您只需设置txtSearch.Visible() = True
或txtSearch.Visible() = False
答案 3 :(得分:0)
在每个单选按钮中将AutoPostBack属性设置为true。那就行了。