摘要:[ASP.NET]動態產生物件
PlaceHolder ph = new PlaceHolder();
TextBox item2=new TextBox();
item2.ID = "item1";
item2.Text = "1";
ph.Controls.Add(new LiteralControl("<table border=\"1\">" +"<tr><td><b>Category ID</b></td>" +"<td><b>Category Name</b></td></tr>"));
ph.Controls.Add(new LiteralControl("<tr><td>"));
ph.Controls.Add(item2);
ph.Controls.Add(new LiteralControl("</td><td>"));
ph.Controls.Add(item2);
ph.Controls.Add(new LiteralControl("</td></tr>"));
ph.Controls.Add(new LiteralControl("<tr bgcolor=\"lightblue\"><td>"));
ph.Controls.Add(item2);
ph.Controls.Add(new LiteralControl("</td><td>"));
ph.Controls.Add(item2);
ph.Controls.Add(new LiteralControl("</td></tr>"));
ph.Controls.Add(new LiteralControl("</table>"));
//一定要加FORM.CONTROL不能直接在THIS打!不然會產生要加入標記清單的錯誤
this.form1.Controls.Add(ph);