How to bind data with radio button?

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
 
D

D0tN3t C0d3r

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

HTH,
~bill
 
S

SP

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top