I have a repeater control, and inside it I have two radio buttons selecting Sex (male, female).
When I save the page, I save the selected value, either “M” or “F”, into the data. When I load the page, I want the radio button to be selected based on what’s saved.
So, in this case, my repeater has (Container.DataItem).Sex, which equals ‘M’ or ‘F’. How can I use this data in my radiobuttons to select the appropriate value?
This is the kind of function I’d like to use (but it doesn’t exist):
<asp:RadioButtonList runat="server" SelectedValue='<%# ((Dependent)(Container.DataItem)).Sex %>' />
Please note that I am unable to manipulate the radio buttons in the codebehind because I do not have access to the individual repeater items.
What you need to do is use 2
RadioButtoncontrol (1 for Female, 1 for Male).Then specify the
GroupNamein order to unselect one when the other is selected.Let’s say
GroupName="Sex".Then specify when each control should be checked according to your
DataItem: