Add radio button list items programmatically in asp.net
asp.net, c#
Solution
You don't need to to do a FindCOntrol. As you used the runat="server" attributes, just get the reference of your RadioList via its name "radio1"
protected void Page_Load(object sender, EventArgs e)
{
radio1.Items.Add(new ListItem("Apple", "1"));
}
Problem
I have a radio button list whose items I need to add on `Page_Load` aspx code ``` <asp:radioButtonList ID="radio1" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal"> </asp:radioButtonList> ``` code behind ``` protected void Page_Load(object sender, EventArgs e) { RadioButtonList radioList = (RadioButtonList)Page.FindControl("radio1"); radioList.Items.Add(new ListItem("Apple", "1")); } ``` After the control reaches `radioList.Items.Add` I keep getting the `Object reference not set to instance of an object` error What am I doing wrong?