I have a RadioButtonList:
<asp:RadioButtonList ID="rblMedicationTime" runat="server" onselectedindexchanged="rblMedicationTime_SelectedIndexChanged" DataSourceID="dtsMedicationTime" DataTextField="LookupItem" DataValueField="Id" AutoPostBack="true"></asp:RadioButtonList>
On page load, I want to select a radio button from the list and set its value, for which I have written this line of code:
rblMedicationTime.SelectedValue = clientMedicationSchedule.glTypeId.ToString();
The RadioButtonList is populating successfully, but the value is unable to be selected.
rblMedicationTime.SelectedValue is always “” when I debug the code.
You just need to use
The property object
myRadioButtonList.SelectedItemcontains all values from the selected item of a Radio Button list or a DropDown listto set the value programmatically all you have to do is:
You can see that you have several ways to Get but only one to Set:
myRadioButtonList.SelectedIndex–> Gets or SetsmyRadioButtonList.SelectedValue–> GetsmyRadioButtonList.SelectedItem–> Gets