日期:2014-05-18  浏览次数:20536 次

大家给一个ASP.NET动态创建控件的例子吧
最好是C#的

------解决方案--------------------
占位。接分。
然后帮你想。。。
------解决方案--------------------
用这个吧 <asp:placeholder id= "Templet " runat= "server "> </asp:placeholder>
Literal newColumn = new Literal();
newColumn.Text = " <table width= '100% ' border= '0 ' cellspacing= '0 ' cellpadding= '0 '> ";

this.Templet.Controls.Add(newColumn);
for(int i=1;i <3;i++)
{
Literal newColumn1 = new Literal();
newColumn1.Text = " <tr align= 'center '> ";
this.Templet.Controls.Add(newColumn1);

for(int j=1;j <3;j++)
{

if(TempletReader.Read())
{
Literal newColumn2 = new Literal();
newColumn2.Text = " <td width= '50% '> <table width= '100% ' border= '0 ' cellspacing= '0 ' cellpadding= '5 '> ";
Literal newColumn3 = new Literal();
newColumn3.Text = " <tr> <td align= 'center '> ";

Literal newColumn4 = new Literal();
newColumn4.Text = " </td> </tr> <tr> <td align= 'center '> ";

Literal newColumn5 = new Literal();
newColumn5.Text = " </tr> </table> </td> ";

HyperLink txtTemplet = new HyperLink();
txtTemplet.ImageUrl= "../Templet_asp/pic/small/ "+TempletReader[ "t_code "].ToString().Trim()+ ".gif ";
txtTemplet.NavigateUrl= "../Templet_asp/pic/ "+TempletReader[ "t_code "].ToString().Trim()+ ".gif ";
txtTemplet.Target= "main ";



HyperLink txtTempletup = new HyperLink();
txtTempletup.Text = "[我要这个] ";
txtTempletup.NavigateUrl = "Admin_templetup.aspx?templetid= "+TempletReader[ "t_code "].ToString()+ "&action=asp ";

Literal TempletName = new Literal();
TempletName.Text = TempletReader[ "t_name "].ToString().Trim();

myList.Add(TempletReader[ "id "].ToString().Trim());

this.Templet.Controls.Add(newColumn2);
this.Templet.Controls.Add(newColumn3);

this.Templet.Controls.Add(txtTemplet);

this.Templet.Controls.Add(newColumn4);

this.Templet.Controls.Add(TempletName);

this.Templet.Controls.Add(txtTempletup);

this.Templet.Controls.Add(newColumn5);



}


}
Literal newColumn6 = new Literal();
newColumn6.Text = " </tr> ";
this.Templet.Controls.Add(newColumn6);
}
Literal newColumn7 = new Literal();
newColumn7.Text = " </table> ";
this.Templet.Controls.Add(newColumn7);