请问 如果有一个文本框和一个按钮 当我在文本框里输入数字时 单击按钮之后 页面上会自动生成与数字相对应的表格 如何实现 谢谢了

解决方案 »

  1.   

    自己在.cs里面生成相应的代码,如:
    string table="<table border=0>"``````
    最好将生成的字符串加起来Response()出来
      

  2.   

    用循环输出</tr>旧可以了        Label1.Text = "<table>";
            for (int i=0 ;i<int.Parse(TextBox1.Text);i++)
            {
                Label1.Text += "<tr><td>测试数据</td></tr>";
            }
            Label1.Text += "</table>";
      

  3.   


          把上面的 Label1.Text = "<table>";
          改成
    Label1.Text = "<table border=1 >";
    就能看到表格了
      

  4.   

    protected void Button4_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(this.TextBox6.Text);
            for (int ii = 0; ii < a; ii++) {
                Label Label1 = new Label();
                Label1.Text = "<table border=1 >";
                for (int i = 0; i < a; i++)
                {
                    Label1.Text += "<tr><td>测试数据</td></tr>";
                }
                Label1.Text += "</table>";        }
        }
    代码是这样的 出不来啊
      

  5.   

    6楼的仁兄的办法我也想到了 可是无法实现啊
    代码如下
     public void qq() {
            string str = "";
            str += "<table border=1 cellpadding=0 cellspacing=0 width=250px height=140px>";        
            str += "<tr><td>id</td><td>name</td>";
            str += "<td>age</td><td>sex</td></tr>";      
            str += "</table>";
            this.div5.InnerHtml = str;
        }
      

  6.   

    你创建那么多Label 干什么 用1个Label 就可以了
            Label1.Text = "<table border=1>";
            for (int i=0 ;i<int.Parse(TextBox1.Text);i++)
            {
                Label1.Text += "<tr><td>测试数据</td></tr>";
            }
            Label1.Text += "</table>";
    在我机器上是成功的,要不你用已创建的label试,可能是你动态创建label有问题
      

  7.   


    Cs:public void MakeTable()
    {
       int iRow = int.Parse(txtRow.Text);
       int iCol = int.Parse(txtCol.Text);
       
       string strTable = "<table>";
       
       for(int i = 0 ;i < iRow ;i++ ){
           strTable += "<tr>";
           
           for(int j = 0 ;j < iCol ; j++ ){ 
              strTable += "<td>&nbsp;</td>";
           }
           strTable += "</tr>";
       }   strTable += "</table>";   Response.Write(strTable);
    }
      

  8.   

    用talbel控件,再用循环来处理就可以了(vs2005).
    protected void Button1_Click (object sender, System.EventArgs e)
    {
       // Total number of rows.
       int rowCnt;
       // Current row count.
       int rowCtr;
       // Total number of cells per row (columns).
       int cellCtr;
       // Current cell counter
       int cellCnt;   rowCnt = int.Parse(TextBox1.Text);
       cellCnt = int.Parse(TextBox2.Text);   for(rowCtr=1; rowCtr <= rowCnt; rowCtr++) {
          // Create new row and add it to the table.
          TableRow tRow = new TableRow();
          Table1.Rows.Add(tRow);
          for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++) {
             // Create a new cell and add it to the row.
             TableCell tCell = new TableCell();
             tCell.Text = "Row " + rowCtr + ", Cell " + cellCtr;
             tRow.Cells.Add(tCell);
          }
       }
    }
      

  9.   

    谢谢楼上的朋友 循环输出表格我会的 现在就是要输入表格的数量
    比如我输入6 点击按钮就会出现6个table 
    代码如下
    Label1.Text = "<table border=1 cellpadding=0 cellspacing=0 width=250px height=140px>";
            for (int i = 0; i < int.Parse(TextBox1.Text); i++)
            {
                
                Label1.Text += "<tr><td>id</td><td>name</td><td>age</td><td>sex</td></tr>";
                Label1.Text += "<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>";            
            }
            Label1.Text += "</table>";
    现在能出现 但是表格没有分开 请大家帮忙