我创建了一个继承自 RadioButtonList 的类,以便为每个列表项添加一个 GroupName 属性。(为什么它不在那里我不知道)。
这在呈现时按预期工作,但不会在回发时保留所选项目。
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);
}
}
有谁知道我错过了什么?
谢谢。