开发者

Dynamic table in Asp.Net

开发者 https://www.devze.com 2022-12-29 12:38 出处:网络
Hi guys here I\'ve created d dynamic table and how can i set 开发者_如何学JAVAd properties of the table like height, width and etc? Pls help me.. Thanks...

Hi guys here I've created d dynamic table and how can i set 开发者_如何学JAVAd properties of the table like height, width and etc? Pls help me.. Thanks...

code

private void GenerateTable(int rowsCount)
 {
   Table table = new Table(); 
   for (int i = 0; i < rowsCount; i++)
   {
     TableRow row = new TableRow();
     TableCell cell = new TableCell();
     TextBox tb1 = new TextBox();
     DropDownList drp1 = new DropDownList();
     tb1.ID= "dname"+i;drp1.ID = "relation" + i;      
     cell.Controls.Add(tb1);
     cell.Controls.Add(drp1);
     row.Cells.Add(cell);table.Rows.Add(row);
   }
   rowsCount++;
   ViewState["RowsCount"] = rowsCount;
 }


// Create a new HtmlTable object.
    HtmlTable table1 = new HtmlTable();

    // Set the table's formatting-related properties.
    table1.Border = 1;
    table1.CellPadding = 3;
    table1.CellSpacing = 3;
    table1.BorderColor = "red";

    // Start adding content to the table.
    HtmlTableRow row;
    HtmlTableCell cell;
    for (int i = 1; i <= 5; i++)
    {
        // Create a new row and set its background color.
        row = new HtmlTableRow();
        row.BgColor = (i % 2 == 0 ? "lightyellow" : "lightcyan");

        for (int j = 1; j <= 4; j++)
        {
            // Create a cell and set its text.
            cell = new HtmlTableCell();
            cell.InnerHtml = "Row: " + i.ToString() +
              "<br>Cell: " + j.ToString();

            // Add the cell to the current row.
            row.Cells.Add(cell);
        }

        // Add the row to the table.
        table1.Rows.Add(row);
    }

    // Add the table to the page.
    this.Controls.Add(table1);

This doesn't work for you?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号