Sunday, August 2, 2009

Add RadioButtonList at run time(asp.net 1.1)(c#)?

i used following code for adding RadioButtonList at run time:


RadioButtonList j=new RadioButtonList();


ListItem g=new ListItem("check1","check");


Controls.Add(j);


j.Items.Add(g);





but i get this error :( Control '_ctl0_0' of type 'RadioButton' must be placed inside a form tag with runat=server )


note: my code insert at %26lt;form runat :server%26gt;%26lt;/form%26gt;

Add RadioButtonList at run time(asp.net 1.1)(c#)?
You need to place the radiobuttonlist inside of a container that is on the page. You can use a asp:ContentPlaceholder or asp:Panel. Place one of those on the page and you can add the radiobutton list to that control.





aspx file:





%26lt;asp:panel runat="server" id="panel1" %26gt;


%26lt;/asp:panel%26gt;





c# code behind:


RadioButtonList j=new RadioButtonList();


j.Items.Add(new ListItem("check1","check"));


this.panel1.Controls.Add(j);





This should work for you. Good luck...


No comments:

Post a Comment