請首先查看:ASP.NET入門教程:HTML服務器控件。簡單講述了HTML服務器控件的使用方法。
下面開始講解:HtmlTableRow控件
HtmlTableRow控件用來控制 <tr> 元素。在HTML中,<tr> 元素用來建立表格行。
1、在此示例中我們在一個.aspx文件中聲明兩個HtmlSelect控件,一個HtmlInputButton控件,及一個HtmlTable控件(要記住把控件嵌入HtmlForm控件中)。用戶可以選擇行數和單元格數。當提交按鈕被觸發的時候,submit子程序被執行。submit子程序將根據用戶的輸入來生成表格。加此信息網頁教學網(webjx.com)發布目的是為了防止你變懶!webjx.com不主張采集!
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
Dim row,numrows,numcells,j,i
row=0
numrows=rows1.Value
numcells=cells1.Value
for j=1 to numrows
Dim r As New HtmlTableRow()
row=row+1
for i=1 to numcells
Dim c As New HtmlTableCell()
c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
r.Cells.Add(c)
next
t1.Rows.Add(r)
t1.Visible=true
next
End Sub
</script>
<html>
<body>
<form runat="server">
<p>Table rows:
<select id="rows1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br />Table cells:
<select id="cells1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br /><br />
<input type="submit" value="Display Table" runat="server" OnServerClick="submit">
</p>
<table id="t1" border="1" runat="server" visible="false"/>
</form>
</body>
</html>
2、在此示例中我們在一個.aspx文件中聲明一個HtmlTable控件及一個HtmlInputButton控件(要記住把控件嵌入HtmlForm控件中)。當提交按鈕被觸發的時候,submit子程序被執行。submit子程序將修改表格的背景色和邊框色,同時改變單元格中的內容。本信息代表文章來源網頁教學webjx.com請大家去www.webjx.com浏覽!
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
dim i,j
table1.BGColor="yellow"
table1.BorderColor="red"
for i=0 To table1.Rows.Count-1
for j=0 To table1.Rows(i).Cells.Count-1
table1.Rows(i).Cells(j).InnerHtml="Row " & i
next
next
End Sub
</script>
<html>
<body>
<form runat="server">
<table id="table1" border="1" runat="server">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
<br />
<input type="button" value="Change Contents" OnServerClick="submit" runat="server"/>
</form>
</body>
</html>