使用按钮单击事件的radiobutton.checked值 [英] radiobutton.checked value with button click event

查看:110
本文介绍了使用按钮单击事件的radiobutton.checked值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个网页包含两个选项按钮和命令按钮。我需要检查命令按钮事件中的radiobutton.checked值。问题是在单击命令按钮后单选按钮选项松开其值,因此if语句将永远不会工作。怎么预防这个?有人可以帮我吗?



代码:

hi all,

i have a web page contains two option buttons and command button. i need to check the radiobutton.checked value in the command button event. the problem is after clicking the command button the radio button option loose its value, so the if statement will never work. how to prevent this? can anyone help me please?

the code:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
       
            For i = 1 To tblResult.Rows(0).Cells.Count - 1
                obj = tblResult.Rows(0).Cells(i).Controls(0)
                formIdOption = obj
                If formIdOption.Checked Then
                    formId = CInt(formIdOption.ID)
                    Exit For
                End If
            Next
End Sub





formIdOption.Checked永远是假的。



formIdOption.Checked is always false.

推荐答案

试试这个

try this
Dim rb As New RadioButton()
For Each tr As TableRow In QuestionTable.Controls
	For Each tc As TableCell In tr.Controls
		If TypeOf tc.Controls(0) Is RadioButton Then
			rb = DirectCast(tc.Controls(0), RadioButton)
			If rb.Checked Then
				Dim aa As String = rb.ID
			End If
			Exit For
		End If
	Next
Next





希望这有助于



Hope this helps


这篇关于使用按钮单击事件的radiobutton.checked值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆