PDA

View Full Version : Radiobutton.Value



Nime
Nov 16, 2009, 2:02 PM
Radiobutton.Value is always true (if checked) or false (not checked). In classical html, a radiobutton may has any value.

In a RadioGroup, it's hard to determine which radiobutton is checked. If radiobutton has a value than it must be checked, if it's empty/null/unset then it must me unchecked. That's it.




I use value in radiobutton's ID as extension, ie: rbState0 for 0, rbState1 for 1 and rbState5 for 5... These are buttons in radigroup rgState.


To set right button in a group at once:




rgState.Items.ForEach(checkbox => checkbox.Checked = checkbox.ID == rgState.ID + Convert.ToInt16(query.Result.Rows[0]["state"]) ? true : false);





To read the checked button in a group:


string checked = rgState.CheckedItems.Count != 1 ? "" : rgState.CheckedItems[0].ID.Substring(rgState.ID.Length, rgState.CheckedItems[0].ID.Length - rgState.ID.Length)));









That's the easiest way to process "only one button checked at a time" situation, I found...


Thanks.