我有这个代码,它在表中创建一个表。 在外表的最后一个col中有一个链接,当点击它时它会打开内部表。
代码:
HTML:
<div id="shutfuyotTable" runat="server">
<table class="tblShutaf" dir="rtl" runat="server">
<thead>
<tr>
<td>num</td>
<td>name</td>
<td>sum1</td>
<td>sum2</td>
<td>notes</td>
<td>moreData</td>
</tr>
</thead>
<tbody>
<tr>
<td>row1</td>
<td>row1</td>
<td>row1</td>
<td>row1</td>
<td>row1</td>
<td><a href='#' id="row1" class='js-showmore'>row1</a>
</td>
</tr>
<tr class="moredata">
<td colspan="5">
<table id="Table1">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>row2</td>
<td>row2</td>
<td>row2</td>
<td>row2</td>
<td>row2</td>
<td><a href='#' id="row2" class='js-showmore'>row2</a>
</td>
</tr>
<tr class="moredata">
<td colspan="5">
<table id="Table2">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>row3</td>
<td>row3</td>
<td>row3</td>
<td>row3</td>
<td>row3</td>
<td><a href='#' id="row3" class='js-showmore'>row3</a>
</td>
</tr>
<tr class="moredata">
<td colspan="5">
<table id="Table3">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>
Jquery的:
$(function() {
$(".js-showmore").on("click", function() {
$(this).closest("tr").next(".moredata").toggle();
});
});
CSS:
.moredata {
display: none;
}
我想做同样的事情,但我想从服务器端创建表(vb) 我将从大型计算机获取数据,但不知道out表中有多少行。 在内表中将是5行。
我知道我需要在Page_Load中进行,但不知道从哪里开始。 (也许做一个tmpstr stringBuilder并连接到div的id?!?)
我很乐意得到一些帮助。
答案 0 :(得分:0)
Dim table As new HtmlTable
table .Attributes.Add("class","test")
Dim row As HtmlTableRow
Dim cell As HtmlTableCell
For i As Integer = 0 To rowNumber
row = new HtmlTableRow
cell = new HtmlTableCell
cell.InnerHtml = "data"
row.Cells.Add(cell)
yourtable.Rows.Add(row)
Next
yourPlaceHolder.Controls.Add(table)