我想给当满足一定条件时动态的给页面添加一个控件,于是我在Page_Load()方法中写了这样的代码:Button bt = new Button();
        bt.Text = "Dymatic added";
        bt.Visible = bool.Parse("true");
// 没有找到类似page.add(bt)这样的方法
但是该代码未出现在页面上。是不是控件只能加在容器内?

解决方案 »

  1.   

    while(dr.Read())
    { LinkButton hl=new LinkButton();
    hl.ResolveUrl("TechCorp.aspx");
    hl.Text="学歴"+"("+dr["S_Count"].ToString()+")"; TableCell tc1=new TableCell();
    tc1.Controls.Add(hl);
    TableCell tc2=new TableCell();
    tc2.Controls.Add(hl);
    TableCell tc3=new TableCell();
    tc3.Controls.Add(hl);
    TableCell tc4=new TableCell();
    tc4.Controls.Add(hl);
    TableCell tc5=new TableCell();
    tc5.Controls.Add(hl); TableRow tr=new TableRow();
    tr.Cells.Add(tc1);
    tr.Cells.Add(tc2);
    tr.Cells.Add(tc3);
    tr.Cells.Add(tc4);
    tr.Cells.Add(tc5); table.Rows.Add(tr);
    }
      

  2.   

    Button bt = new Button();
            bt.Text = "Dymatic added";
    Panel p=new Panel();
    p.Controls.Add(bt);
      

  3.   

    一般的容器类都有Controls属性,可以通过Add()方法来添加控件
      

  4.   

    Controls.Add()好好看看msdn吧,对你有帮助的
      

  5.   

    不是看起来那么简单的。
    我用  this.Page.Controls.Add(bt);报出没有runat="server"的异常
    “  Control 'ctl02' of type 'Button' must be placed inside a form tag with runat=server.“