开发者

how to add control to the page?

Controls must be added to a page like this.

<div>
<% 
for(int i=0; i<10; i++)
{
   Label lab=new Label();
   lab.Text="Text"+i;
   Response.Write(lab);
}
%>
</div>开发者_JAVA技巧

OR

<div>
<% for(int i=0; i<10; i++)
{
    Response.Write("<asp:Label runat='server' Text='Text' />");
}
%>
</div>

How to do it?


<div>
  <asp:PlaceHolder ID="phControls" runat="server"></asp:PlaceHolder>
</div>

then in your code behind

for(int i=0; i<10; i++)
{
  Label lab=new Lable()
  lab.Text="Text"+i;
  lab.ID = "lbl" + i;
  phControls.Controls.Add(lab);
}

This way you can control where the controls are place. Otherwise they will be added at the end of the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜