通过radiobutton启用或显示文本框

时间:2013-11-20 06:25:46

标签: vb.net

我希望在用户检查单选按钮时启用或显示文本框,如果答案为否,则无法启用或显示文本框。 在我忘记gridview中的所有这些之前

谢谢

2 个答案:

答案 0 :(得分:1)

在Grid的 RowDataBound 事件中,首先找到您的控件。然后使用您需要的条件设置文本框的可见性。

Protected Sub gvTimeSlots_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvTimeSlots.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim RadioButton1 As System.Web.UI.WebControls.RadioButton = e.Row.FindControl("RadioButton1")
        Dim TextBox1 As System.Web.UI.WebControls.TextBox = e.Row.FindControl("TextBox1")
    If RadioButton1.Value="Yes" Then
       TextBox1.Enabled = True
       // If you want to set the visibility use
       TextBox1.Visible = True
    End If
End Sub

答案 1 :(得分:0)

我使用了很多我在互联网上发现它们的解决方案。这一个

受保护的Sub reject_CheckedChanged(ByVal sender As Object,ByVal e As System.EventArgs)

    Dim rbd As RadioButton = CType(sender, RadioButton)
    Dim grdrow As GridViewRow = CType(rbd.NamingContainer, GridViewRow)

    Dim reject As RadioButton = CType(grdrow.Cells(9).Controls(0).FindControl("reject"), RadioButton)
    Dim t1 As TextBox = CType(grdrow.Cells(9).Controls(0).FindControl("t1"), TextBox)

    If reject.Checked = True Then
        t1.Visible = True

End Sub

当我检查radiobutton时,当AutoPostedBack为True时,它将取消选中(对于2个解决方案) 我的gridview名称gvorders

相关问题