I have created a class that inherits from RadioButtonList in order to add a GroupName attribute to each list item. (why it was not there already I have no idea).
This works as expected when it is rendered, but does not persist the selected items on postback.
public class GroupedRadioButtonList : RadioButtonList
{
[Bindable(true), Description("GroupName for all radio buttons in list.")]
public string GroupName
{
get;
set;
}
protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, System.Web.UI.HtmlTextWriter writer)
{
RadioButton radioButton = new RadioButton();
radioButton.Page = this.Page;
radioButton.GroupName = this.GroupName;
radioButton.ID = this.ClientID + "_" + repeatIndex.ToString();
radioButton.Text = this.Items[repeatIndex].Text;
radioButton.Attributes["value"] = this.Items[repeatIndex].Value;
radioButton.Checked = this.Items[repeatIndex].Selected;
radioButton.TextAlign = this.TextAlign;
radioButton.AutoPostBack = this.AutoPostBack;
radioButton.TabIndex = this.TabIndex;
radioButton.Enabled = this.Enabled;
radioButton.RenderControl(writer);
}
}
Does anyone know what I am missing?
Thanks.