动态添加复选框asp.net [英] Dynamically add checkboxes to asp.net
问题描述
我试图复选框添加到动态网页
I am trying to add Checkboxes dynamically to webpage
string[] words = masg.Split('~');
int size = words.Length;
CheckBox[] cbl = new CheckBox[size];
for (int i = 0; i < words.Length; i++)
{
cbl[i] = new CheckBox();
cbl[i].Text = words[i].ToString();
this.Controls.Add(cbl[i]);
// Response.Write("\n" + words[i]);
}
我收到错误
checkbox类型的控制ctl01'必须放在与RUNAT =服务器的表单标签内。
我应该如何进行?使aspx页面上的哪些变化?请帮助。
How should I proceed ? What changes to make on aspx page ? Please help.
推荐答案
您应该改变它在表单中添加,因为这个
正在引用您的页面。和你所创建程序或用 =服务器添加页面上的任何服务器控件
应放置在窗体标签内。
You should change it to add in form, because this
is referencing your Page. and any server control which you are creating programmatic or by adding on page with runat="server"
should place inside a form tag.
像
this.Form.Controls.Add(cbl[i]);
或在窗体上放置一个占位符或面板。比你可以在其中添加
or place a placeholder or panel on the form. and than you can add in it
像
placeholder1.Controls.Add(cbl[i]);
如果您的.aspx不包含表单标签,那么你应该放置一个表单标签有
If your .aspx does not contain a form tag, then you should place a form tag there
像
<form runat="server" id="form1">
//Other mark up or server controls.
</form>
这篇关于动态添加复选框asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!