2009-12-27 52 views
0

对于创建运行时的LinkBut​​ton我用这个代码创建运行时的LinkBut​​ton

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); 

     } 

    } 

该错误发生...

“类型‘的LinkBut​​ton’的控制‘ctl34’必须放在一个窗体标记内与RUNAT =服务器。“

请给我soluation此

回答

2

确保你表(t)是表单标签内。

1

最有可能的表格位于哪个表中,您添加的LinkBut​​ton并未指定runat = server属性,或者此表格根本不在表格中。

确保你有这样的事情。

<form runat="server"> 
<!--table to which you are adding your rows--> 
</form> 
0

先给ID到表单中说<form id="myForm" runat="server">

然后在后面的代码,你可以像你这样

myForm.Controls.Add(t); 
+0

固定您的回复添加表格的形式。 – Blindy 2009-12-28 12:27:00