各リストアイテムにGroupName属性を追加するために、RadioButtonListから継承するクラスを作成しました。(なぜそれがまだそこになかったのか私にはわかりません)。
これは、レンダリング時に期待どおりに機能しますが、選択したアイテムをポストバックで保持しません。
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);
}
}
誰かが私が欠けているものを知っていますか?
ありがとう。