我有一个单选按钮列表,我需要在Page_Load
中添加其项。
aspx代码:
<asp:radioButtonList ID="radio1" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
</asp:radioButtonList>
代码后台protected void Page_Load(object sender, EventArgs e)
{
RadioButtonList radioList = (RadioButtonList)Page.FindControl("radio1");
radioList.Items.Add(new ListItem("Apple", "1"));
}
当控件到达 radioList.Items.Add
时,我一直收到Object reference not set to instance of an object
的错误提示。
我做错了什么?
radio1
是否在另一个 ASP.NET 控件内,例如 Repeater 或类似的控件中? - Claudio Redi