C# 创建运行时链接按钮
为了创建运行时链接按钮,我使用了以下代码C# 创建运行时链接按钮,c#,C#,为了创建运行时链接按钮,我使用了以下代码 for (int i = 0; i <= 10; i++) { r = new TableRow(); t.Rows.Add(r); for (int j = 0; j <= 2; j++) { c = new TableCell(); r.Cells.Add(c); LinkB
for (int i = 0; i <= 10; i++)
{
r = new TableRow();
t.Rows.Add(r);
for (int j = 0; j <= 2; j++)
{
c = new TableCell();
r.Cells.Add(c);
LinkButton btnLnk = new LinkButton();
btnLnk.Text = "Hello";
btnLnk.Visible = true;
btnLnk.CommandName = "Test";
btnLnk.CommandArgument = "1";
btnLnk.ID = "Hi";
c.Controls.Add(ll);
}
}
for(int i=0;i确保您的表(t)在表单标记内。确保您的表(t)在表单标记内。最有可能的情况是,添加链接按钮的表所在的表单没有指定runat=server属性,或者该表根本不在表单中
确保你有这样的东西
<form runat="server">
<!--table to which you are adding your rows-->
</form>
最有可能的情况是,要添加链接按钮的表所在的表单没有指定runat=server属性,或者该表根本不在表单中
确保你有这样的东西
<form runat="server">
<!--table to which you are adding your rows-->
</form>
首先给你的表单提供id,比如说
然后在代码隐藏中,您可以像这样向表单中添加表
myForm.Controls.Add(t);
首先给表单提供id,比如说
然后在代码隐藏中,您可以像这样向表单中添加表
myForm.Controls.Add(t);