如何在内部添加htmltable行<;t车身>;来自C#codebehind?

如何在内部添加htmltable行<;t车身>;来自C#codebehind?,c#,asp.net,C#,Asp.net,我有下面的HTML表格结构 <table id="myTable" runat="server"> <thead> <tr> <th>Column1</th> <th>Column2</th> </tr> </thead> <tbody > </tbody> &

我有下面的HTML表格结构

<table id="myTable" runat="server">
    <thead>
        <tr>
           <th>Column1</th>
           <th>Column2</th>
        </tr>
    </thead>
   <tbody >

   </tbody>
</table> 
请建议我如何将tablerow添加到html表格tbody内标签中。提前感谢:-)

试试这个

Table table = new Table();
TableRow tblRow;
TableCell tblCell;

tblRow= new TableRow();
tblRow.TableSection = TableRowSection.TableHeader;
tblCell= new TableCell();
tblCell.Text = "Header";
tblRow.Cells.Add(tblCell);
table.Rows.Add(tableRow);

tblRow= new TableRow();
tblRow.TableSection = TableRowSection.TableBody;
tblCell= new TableCell();
tblCell.Text = "Body";
tblRow.Cells.Add(tblCell);
table.Rows.Add(tblRow);

tblRow= new TableRow();
tblRow.TableSection = TableRowSection.TableFooter;
tblCell= new TableCell();
tblCell.Text = "Footer";
tblRow.Cells.Add(tblCell);
table.Rows.Add(tblRow);

WebForm.Controls.Add(table);
试试这个

Table table = new Table();
TableRow tblRow;
TableCell tblCell;

tblRow= new TableRow();
tblRow.TableSection = TableRowSection.TableHeader;
tblCell= new TableCell();
tblCell.Text = "Header";
tblRow.Cells.Add(tblCell);
table.Rows.Add(tableRow);

tblRow= new TableRow();
tblRow.TableSection = TableRowSection.TableBody;
tblCell= new TableCell();
tblCell.Text = "Body";
tblRow.Cells.Add(tblCell);
table.Rows.Add(tblRow);

tblRow= new TableRow();
tblRow.TableSection = TableRowSection.TableFooter;
tblCell= new TableCell();
tblCell.Text = "Footer";
tblRow.Cells.Add(tblCell);
table.Rows.Add(tblRow);

WebForm.Controls.Add(table);

为什么不在代码隐藏中创建整个表?或者使用GridView?为什么不在代码隐藏中创建整个表?或者使用GridView?html控件不可能吗?不,这些是System.Web.UI.WebControl。我想在HtmlTable(System.Web.UI.htmlControl)上做同样的事情。。我很抱歉。。这是一个疏忽。这段代码创建了一个AD。html控件不可能吗?不,它们是System.Web.UI.WebControl。我想在HtmlTable(System.Web.UI.htmlControl)上做同样的事情。。我很抱歉。。这是一个疏忽。这段代码创建了THead。