环境:windows2003,asp.net(C#)web应用程序
向Panel中添加现在有的Panel;
代码如下:
Label lbl=new Label();
lbl.Text="it's test";
this.Panel2.Controls.Add(lbl);
this.Panel1.Controls.Add(this.Panel2);
向Panel2中添加lbl没有问题,但是在Panel1中添加Panel2时却添加不上。跪求各位高手指点!!

解决方案 »

  1.   

    你确定么?出什么错?Panel2与Panel1的关系是?下面这编码可以的<form runat="server">
    <asp:Panel id="Panel1" runat="server" Style="border:2 solid red">
     <asp:TextBox id="txt" runat="server" />
    </asp:Panel><asp:Panel id="Panel2" runat="server" Style="border:1 solid blue">
     <asp:TextBox id="txt2" runat="server" />
    </asp:Panel><asp:Button id="btn" runat="server" Text="Refresh" />
    </form><script language="C#" runat="server">
    void Page_Load(object sender, EventArgs e)
    {
    Label lbl=new Label();
    lbl.Text="it's test";
    this.Panel2.Controls.Add(lbl);
    this.Panel1.Controls.Add(this.Panel2);
    }
    </script>
      

  2.   

    saucer(思归)
    我的代码和你的思路一样。
    你的方法我用了,和我开始时出现的的结果一样。
    lbl能添加到Panel2里,但是Panel2并没有被添加到Panel1。
    运行过程中没有出错,但是显示出的来结果不是我想要的那种。Panel1 和 Panel2都是我直接从工具箱拖过来的,两者之间没有关系。
    我要做的是:有一个结构框架,是来用来显示数据的,但是有多条数据,所以我要创建多个一样的结构框架。因为这些框架是HTML画出来的,我只是在里面加了几个服务器控件。因为这样我才想到在Panel中添加Panel。如果你有更的办法,请告诉我,谢谢!
      

  3.   

    已经添加了,你查看一下HTML源代码就可以了
      

  4.   

    已经添加了,你查看一下HTML源代码就知道了
      

  5.   

    >>>但是显示出的来结果不是我想要的那种但只说明是你加的位置不对,建议你别用Panel,用Table
      

  6.   

    saucer(思归) 对table的用法,我不了解,可以给一段提示性的代码吗?
    谢谢
      

  7.   

    感谢::saucer(思归)谢谢你的提示,是我走入的误区,如果能及早用table话,就更方便了。