0

我希望仅在选择单选按钮时出现文本框。我尝试使用 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

我很确定无论如何都有一种非常有效的方法。

4

4 回答 4

0

正如 tymeJV 提到()的,删除Visible()

此外,您不需要禁用其他单选按钮,除非它们专门单独分组。

由于无论选择了哪个单选按钮,您总是使按钮/文本框可见,因此您无需检查单选按钮的值。您的活动应如下所示(更改其他人以效仿)

Protected Sub radItem_CheckedChanged(sender As Object, e As EventArgs) Handles radItem.CheckedChanged
    btnSearch.Visible = True
    txtSearch.Visible = True
End Sub
于 2013-03-19T19:51:49.563 回答
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
于 2013-03-19T21:03:10.740 回答
0

票价,将“GroupName”属性添加到您的单选按钮后,您无需设置其他 Radios 的 Text 或 Checked 状态,它会自动更新。

对于显示/隐藏文本框,您只需要设置txtSearch.Visible() = TrueORtxtSearch.Visible() = False

于 2013-03-20T15:08:05.063 回答
0

在每个单选按钮中将 AutoPostBack 属性设置为 true。那么它将起作用。

于 2014-12-08T11:25:31.567 回答