Programatically Setting DropDownList / RadioButtonList
Category: DotNet
So, often we have a radio button list or drop down list that we want to be selected to a certain item when the page loads. You will notice that the only available setter property is the RadioButtonList1.SelectedIndex. It is possible to do set it to the correct SelectedValue using the following code behind (assuming you List has items or is databound):
ListItem item = RadioButtonList1.Items.FindByValue("value");
if (item != null)
{
RadioButtonList1.SelectedIndex = RadioButtonList1.Items.IndexOf(item);
}
Replace the "value" string for whatever value it is you want selected. The "value" must be a valid value item in the drop down or radio button list.