比如我要实例化80个,应该怎么弄,布局是每行4个那种的

解决方案 »

  1.   

    在外面定义个TextBox textbox;
    再写两层循环
      

  2.   

    冒泡接分变态呀在cs文件中添加或者在datalist模板中放一个?
      

  3.   

    如果是web的,可以用个talbe
    StringBulider textbox = new StringBulider();
    textbox.Append("<table>");
    for(int i = 0; i < 20; ++i)
    {
    textbox.Append("<tr>");
    for(int j = 0; j < 4; ++j)
    {
    textbox.Append("<td>");
    textbox.Append("<input value='text' />");
    textbox.Append("</td>");
    }
    textbox.Append("</tr>");
    }
    textbox.Append("</table>");
      

  4.   

    不是web
    我菜鸟,希望大家指点一下
      

  5.   

    动态添加textbox.
    <asp:Button ID="createbutton" runat="server" Text="批量创建" 
                onclick="createbutton_Click" />
    <asp:Table ID="HolderTable"  runat="server"></asp:Table> protected override void OnLoad(EventArgs e)
        {
            CreateControl();
        }     protected void createbutton_Click(object sender, EventArgs e)
        {
            if (ViewState["CreateControl"] == null)
            {
                ViewState["CreateControl"] = true;
                CreateControl();
            }
        }     void CreateControl() {
           if (ViewState["CreateControl"]==null) return;  
            for (int x = 0; x < 20; x++)
            {
                TableRow row = new TableRow();
                for (int y = 0; y < 4; y++)
                {
                    TableCell cell = new TableCell(); 
                    Button bt = new Button();
                    bt.Text = string.Format("  x={0},y={1}  ", x, y);
                    cell.Controls.Add(bt); 
                    row.Cells.Add(cell);
                } 
                HolderTable.Rows.Add(row);
            }
        } 
      

  6.   

    void CreateControl() { 
          if (ViewState["CreateControl"]==null) return;  
            for (int x = 0; x < 20; x++) 
            { 
                TableRow row = new TableRow(); 
                for (int y = 0; y < 4; y++) 
                { 
                    TableCell cell = new TableCell(); 
                    Textbox txt= new Textbox(); 
                    txt.ID=x;
                    txt.Text = string.Format("x={0},y={1}", x, y); 
                    cell.Controls.Add(txt); 
                    row.Cells.Add(cell); 
                } 
                HolderTable.Rows.Add(row); 
            } 
        } 
    或   this.Panel1.Controls.Add(txt); 
      

  7.   

    设置一个四列的datagridview,然后在每个单元格中添加textbox
      

  8.   

    TextBox txt;
    Panel p= new Panel();
    for(int i=1i<=0;i++)
    {
        txt== new TextBox();
        p.Control.add(txt);
        if(i%4==0)
        {
           Litier l= new Litier();
           l.Text="<br />"
        }
    }
      

  9.   


            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                Button[] button1 = new Button[80];
                int k = 0;
                int j = 0;
                for (var i = 0; i < button1.Length; i++)
                {
                    button1[i] = new Button();
                    this.Controls.Add(button1[i]);
                    if (k> 3)
                    {
                        k = 0;
                        j++;
                    }
                    button1[i].Text = i.ToString();
                    button1[i].Location = new Point(80*++k, 30*j);
                }
            }
      

  10.   

    添加tableLayoutPanel 编辑为20行4列for (int i = 0; i < 20; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        TextBox tb = new TextBox();
                        tb.Text = "text" + i.ToString() + j.ToString();
                        tableLayoutPanel1.Controls.Add(tb, j, i);
                    }
                }
      

  11.   

     /// <summary>
            /// 
            /// </summary>
            /// <param name="row">表示列</param>
            /// <param name="line">表示行</param>
            public void InitBtn(int row, int line)
            {
                Button btn;
                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < line; j++)
                    {
                        btn = new Button();
                        btn.AutoSize = false;
                        btn.Location = new System.Drawing.Point(59,60);
                        btn.Size = new System.Drawing.Size(50,25);
                        btn.Location = new System.Drawing.Point(60+(i*90),60+(j*60));
                        this.Controls.Add(btn);                }
                }
            }
    其他属性自己加了
      

  12.   

    repeater或datalist都可以,最好还是不要循环加~~