How to bind data with radio button?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi experts,

In my application, I have a employee table containing a gender field which
has value "M", "F". I bind gender field to the "checked" property of a group
of 2 radio buttons. I hope to show radio button for Male checked when
underneath data is "M" and radio button for Female checked when data is "F".
User can also click a radio button to decide the gender for a new employee.

But radioButton.checked is a bool value! It does not take text like "M",
"F". Is it possible to change the data type of this property to take string?
Is there any other property I can use?

Thanks,

Karl
 
<code>
radioButtonMale.checked = (field == "M" ? true : false);
radioButtonFemale.checked = (field == "F" ? true : false);
</code>

HTH,
~bill
 
D0tN3t C0d3r said:
<code>
radioButtonMale.checked = (field == "M" ? true : false);
radioButtonFemale.checked = (field == "F" ? true : false);
</code>

If there are going to be lots of radio buttons I would have a static method
on a UI utilites class that takes the string and a radio buttons as
parameters and uses the code like above.

UiUtils.SetCheckedState(radioButtonMale, radioButtonFemale, "M");

SP
 
Thanks, bill.

But it solves only one part of the problem. I also want to set value of
Gender field to "M" when "Male" radio button is clicked. Any suggestion?

regards,

Karl
 
Back
Top