Asp.net 从服务器端向html表添加行
我有这个html代码Asp.net 从服务器端向html表添加行,asp.net,Asp.net,我有这个html代码 <table id="rounded" runat=server style="position:relative;left:-45px;" > <thead> <tr> <th scope="col" class="rounded-company">status</th> <th scope="col" class="rounded-q1"&
<table id="rounded" runat=server style="position:relative;left:-45px;" >
<thead>
<tr>
<th scope="col" class="rounded-company">status</th>
<th scope="col" class="rounded-q1">date</th>
<th scope="col" class="rounded-q1">price</th>
<th scope="col" class="rounded-q1">quantity</th>
<th scope="col" class="rounded-q1">option1</th>
<th scope="col" class="rounded-q1">option2</th>
<th scope="col" class="rounded-q1">paync</th>
<th scope="col" class="rounded-q1">product_id</th>
<th scope="col" class="rounded-q1">sell number</th>
<th scope="col" class="rounded-q4"> name</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="9" class="rounded-foot-left" dir=rtl ><em></em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
</table>
但是asp.net不支持表的InnerHTML
此任务的正确方法是什么?不要在服务器端表中添加标记-在代码隐藏中添加
HtmlTableRow
s
C#:
VB.NET:
Dim tr as HtmlTableRow = New HtmlTableRow()
tr.Cells.Add(New HtmlTableCell(reader4.GetValue(9))
tr.Cells.Add(New HtmlTableCell(reader4.GetValue(8))
...
rounded.Rows.Add(tr)
您可以将表作为服务器对象
int numrows = 3;
int numcells = 2;
for (int j = 0; j < numrows; j++)
{
TableRow r = new TableRow();
for (int i = 0; i < numcells; i++) {
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("row "
+ j.ToString() + ", cell " + i.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
int numrows=3;
int numcells=2;
对于(int j=0;j
你说得对,我查过了。 但您仍然可以使用Rows.Add方法为表添加数据。 我试过了,效果很好:
HtmlTableRow a = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = "test";
a.Cells.Add(cell);
HtmlTableCell cell2 = new HtmlTableCell();
cell2.InnerHtml = "test";
a.Cells.Add(cell2);
HtmlTableCell cell3 = new HtmlTableCell();
cell3.InnerHtml = "test";
a.Cells.Add(cell3);
HtmlTableCell cell4 = new HtmlTableCell();
cell4.InnerHtml = "test";
a.Cells.Add(cell4);
HtmlTableCell cell5 = new HtmlTableCell();
cell5.InnerHtml = "test";
a.Cells.Add(cell5);
HtmlTableCell cell6 = new HtmlTableCell();
cell6.InnerHtml = "test";
a.Cells.Add(cell6);
HtmlTableCell cell7 = new HtmlTableCell();
cell7.InnerHtml = "test";
a.Cells.Add(cell7);
HtmlTableCell cell8 = new HtmlTableCell();
cell8.InnerHtml = "test";
a.Cells.Add(cell8);
HtmlTableCell cell9 = new HtmlTableCell();
cell9.InnerHtml = "test";
a.Cells.Add(cell9);
HtmlTableCell cell10 = new HtmlTableCell();
cell10.InnerHtml = "test";
a.Cells.Add(cell10);
((HtmlTable)rounded).Rows.Add(a);
你的桌子在哪里 嗨Oded,谢谢你的重播-我需要服务器端(vb)的代码,你的代码是javascript@baaroz-不,我的代码是C。您从未指定VB.NET作为语言-下次请正确标记。答案更新为VB.NET示例。
Dim tr as HtmlTableRow = New HtmlTableRow()
tr.Cells.Add(New HtmlTableCell(reader4.GetValue(9))
tr.Cells.Add(New HtmlTableCell(reader4.GetValue(8))
...
rounded.Rows.Add(tr)
int numrows = 3;
int numcells = 2;
for (int j = 0; j < numrows; j++)
{
TableRow r = new TableRow();
for (int i = 0; i < numcells; i++) {
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("row "
+ j.ToString() + ", cell " + i.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
HtmlTableRow a = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = "test";
a.Cells.Add(cell);
HtmlTableCell cell2 = new HtmlTableCell();
cell2.InnerHtml = "test";
a.Cells.Add(cell2);
HtmlTableCell cell3 = new HtmlTableCell();
cell3.InnerHtml = "test";
a.Cells.Add(cell3);
HtmlTableCell cell4 = new HtmlTableCell();
cell4.InnerHtml = "test";
a.Cells.Add(cell4);
HtmlTableCell cell5 = new HtmlTableCell();
cell5.InnerHtml = "test";
a.Cells.Add(cell5);
HtmlTableCell cell6 = new HtmlTableCell();
cell6.InnerHtml = "test";
a.Cells.Add(cell6);
HtmlTableCell cell7 = new HtmlTableCell();
cell7.InnerHtml = "test";
a.Cells.Add(cell7);
HtmlTableCell cell8 = new HtmlTableCell();
cell8.InnerHtml = "test";
a.Cells.Add(cell8);
HtmlTableCell cell9 = new HtmlTableCell();
cell9.InnerHtml = "test";
a.Cells.Add(cell9);
HtmlTableCell cell10 = new HtmlTableCell();
cell10.InnerHtml = "test";
a.Cells.Add(cell10);
((HtmlTable)rounded).Rows.Add(a);