天天看點

table循環顯示記錄

  // 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();

     tRow.Cells.Add(tCell);              

     // Mock up a product ID.

     string prodID = rowCtr + "_" + cellCtr;

     // Add a literal text as control.

     tCell.Controls.Add(new LiteralControl("Buy: "));

     // Create Hyperlink Web Server control and add to cell

     System.Web.UI.WebControls.HyperLink h = new HyperLink();

     h.Text = rowCtr + ":" + cellCtr;

     h.NavigateUrl = "http://www.microsoft.com/china/net";

     tCell.Controls.Add(h);

    }

   }