user3344443
user3344443

Reputation: 485

get value from checkbox asp.net & vb

I wonder in visual studio, what would be the code to acquire the value from the Checkbox. Say, if checked, value=1; if not, value=0. I know for radio button, I can automatically assign the value. But what about the checkbox? Do I even need to register a user control and write a case function such as

_checkResult = value

Select Case _checkResult
Case 1
     CheckBoxA.Checked = True                 
Case 0
     CheckBoxA.Checked = False

End Select

Much appreciated for any help:)

Upvotes: 0

Views: 8304

Answers (1)

jazakari
jazakari

Reputation: 66

To get the value of a checkbox all you need to do is call Checked.

Your code is doing something different though. You are setting the value and a case statement correctly works to do this as long as value is restricted to being either 0 or 1. I would recommend to use a boolean datatype for _checkResult as this ensures that it will always be set. It also makes it easier to set the value as shown below.

CheckBoxA.Checked = _checkResult

Upvotes: 1

Related Questions