HtmlTable イベント

名前 | 説明 | |
---|---|---|
![]() | DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。 ( Control から継承されます。) |
![]() | Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。 ( Control から継承されます。) |
![]() | Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。 ( Control から継承されます。) |
![]() | Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。 ( Control から継承されます。) |
![]() | PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。 ( Control から継承されます。) |
![]() | Unload | サーバー コントロールがメモリからアンロードされると発生します。 ( Control から継承されます。) |

関連項目
HtmlTable クラスSystem.Web.UI.HtmlControls 名前空間
HtmlContainerControl クラス
HtmlTableCell
HtmlTableCellCollection
HtmlTableRow
HtmlTableRowCollection
その他の技術情報
HTML サーバー コントロールHtmlTable クラス
アセンブリ: System.Web (system.web.dll 内)


HtmlTable コントロールを使用して、サーバー上の HTML <table> 要素をプログラムで制御します。これによって Web ページにテーブルを作成できます。
さらに、BgColor、Border、BorderColor、Height、Width の各プロパティを設定して、<table> 要素の外観を動的に変更できます。また、Align、CellPadding、および CellSpacing の各プロパティを設定すると、セルの内容の表示方法を制御できます。
HtmlTable コントロールの行はコントロールの Rows プロパティに格納されます。これによってテーブルの各行にプログラムによってアクセスできます。
![]() |
---|
複合テーブル モデルはサポートされていません。<caption>、<col>、<colgroup>、<tbody>、<thead>、<tfoot> の各要素が入れ子になっている HtmlTable コントロールを持つことはできません。これらの要素は警告なしに削除され、出力 HTML には表示されません。これらのテーブル モデル要素を HtmlTable コントロールの Control.Controls コレクションにプログラムを使って追加しようとすると、例外がスローされます。 |
HtmlTable のインスタンスの初期プロパティ値の一覧については、HtmlTable コンストラクタのトピックを参照してください。

HtmlTable コントロールを使用して、テーブル内の情報を表示する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <script runat="server"> Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) ' Set the properties of the HtmlTable with the ' user selections. Table1.BgColor = BgColorSelect.Value Table1.Border = CInt(BorderSelect.Value) Table1.BorderColor = BorderColorSelect.Value Table1.Height = HeightSelect.Value Table1.Width = WidthSelect.Value End Sub </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3>HtmlTable Example</h3> <table id="Table1" Border="1" BorderColor="black" runat="server"> <tr> <th> Column 1 </th> <th> Column 2 </th> <th> Column 3 </th> </tr> <tr> <td> Cell 1 </td> <td> Cell 2 </td> <td> Cell 3 </td> </tr> <tr> <td> Cell 4 </td> <td> Cell 5 </td> <td> Cell 6 </td> </tr> </table> <hr> Select the display settings: <br><br> BgColor: <select id="BgColorSelect" runat="server"> <option Value="Red">Red</option> <option Value="Blue">Blue</option> <option Value="Green">Green</option> <option Value="Black">Black</option> <option Value="White" Selected>White</option> </select> Border: <select id="BorderSelect" runat="server"> <option Value="0">0</option> <option Value="1" Selected>1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> BorderColor: <select id="BorderColorSelect" runat="server"> <option Value="Red">Red</option> <option Value="Blue">Blue</option> <option Value="Green">Green</option> <option Value="Black" Selected>Black</option> <option Value="White">White</option> </select> <br><br> Height: <select id="HeightSelect" runat="server"> <option Value="0">0</option> <option Value="100">100</option> <option Value="150">150</option> <option Value="200">200</option> <option Value="250">250</option> </select> Width: <select id="WidthSelect" runat="server"> <option Value="0">0</option> <option Value="200">200</option> <option Value="250">250</option> <option Value="300">300</option> <option Value="350">350</option> </select> <br><br> <input type="button" value="Generate Table" OnServerClick ="Button_Click" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <script runat="server"> void Button_Click(Object sender, EventArgs e) { // Set the properties of the HtmlTable with the // user selections. Table1.BgColor = BgColorSelect.Value; Table1.Border = Convert.ToInt32(BorderSelect.Value); Table1.BorderColor = BorderColorSelect.Value; Table1.Height = HeightSelect.Value; Table1.Width = WidthSelect.Value; } </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3>HtmlTable Example</h3> <table id="Table1" Border="1" BorderColor="black" runat="server"> <tr> <th> Column 1 </th> <th> Column 2 </th> <th> Column 3 </th> </tr> <tr> <td> Cell 1 </td> <td> Cell 2 </td> <td> Cell 3 </td> </tr> <tr> <td> Cell 4 </td> <td> Cell 5 </td> <td> Cell 6 </td> </tr> </table> <hr> Select the display settings: <br><br> BgColor: <select id="BgColorSelect" runat="server"> <option Value="Red">Red</option> <option Value="Blue">Blue</option> <option Value="Green">Green</option> <option Value="Black">Black</option> <option Value="White" Selected>White</option> </select> Border: <select id="BorderSelect" runat="server"> <option Value="0">0</option> <option Value="1" Selected>1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> BorderColor: <select id="BorderColorSelect" runat="server"> <option Value="Red">Red</option> <option Value="Blue">Blue</option> <option Value="Green">Green</option> <option Value="Black" Selected>Black</option> <option Value="White">White</option> </select> <br><br> Height: <select id="HeightSelect" runat="server"> <option Value="0">0</option> <option Value="100">100</option> <option Value="150">150</option> <option Value="200">200</option> <option Value="250">250</option> </select> Width: <select id="WidthSelect" runat="server"> <option Value="0">0</option> <option Value="200">200</option> <option Value="250">250</option> <option Value="300">300</option> <option Value="350">350</option> </select> <br><br> <input type="button" value="Generate Table" OnServerClick ="Button_Click" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <script runat="server"> function Button_Click(sender : Object, e : EventArgs) { // Set the properties of the HtmlTable with the // user selections. Table1.BgColor = BgColorSelect.Value; Table1.Border = Convert.ToInt32(BorderSelect.Value); Table1.BorderColor = BorderColorSelect.Value; Table1.Height = HeightSelect.Value; Table1.Width = WidthSelect.Value; } </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3>HtmlTable Example</h3> <table id="Table1" Border="1" BorderColor="black" runat="server"> <tr> <th> Column 1 </th> <th> Column 2 </th> <th> Column 3 </th> </tr> <tr> <td> Cell 1 </td> <td> Cell 2 </td> <td> Cell 3 </td> </tr> <tr> <td> Cell 4 </td> <td> Cell 5 </td> <td> Cell 6 </td> </tr> </table> <hr> Select the display settings: <br><br> BgColor: <select id="BgColorSelect" runat="server"> <option Value="Red">Red</option> <option Value="Blue">Blue</option> <option Value="Green">Green</option> <option Value="Black">Black</option> <option Value="White" Selected>White</option> </select> Border: <select id="BorderSelect" runat="server"> <option Value="0">0</option> <option Value="1" Selected>1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> BorderColor: <select id="BorderColorSelect" runat="server"> <option Value="Red">Red</option> <option Value="Blue">Blue</option> <option Value="Green">Green</option> <option Value="Black" Selected>Black</option> <option Value="White">White</option> </select> <br><br> Height: <select id="HeightSelect" runat="server"> <option Value="0">0</option> <option Value="100">100</option> <option Value="150">150</option> <option Value="200">200</option> <option Value="250">250</option> </select> Width: <select id="WidthSelect" runat="server"> <option Value="0">0</option> <option Value="200">200</option> <option Value="250">250</option> <option Value="300">300</option> <option Value="350">350</option> </select> <br><br> <input type="button" value="Generate Table" OnServerClick ="Button_Click" runat="server"/> </form> </body> </html>
HtmlTable コントロールを動的に作成する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim i As Integer Dim j As Integer Dim row As HtmlTableRow Dim cell As HtmlTableCell ' Get the number of rows and columns selected by the user. Dim numrows As Integer = CInt(Select1.Value) Dim numcells As Integer = CInt(Select2.Value) ' Iterate through the rows. For j = 0 To numrows - 1 ' Create a new row. row = New HtmlTableRow() ' Provide a different background color for alternating rows. If (j Mod 2) = 1 Then row.BgColor = "Gray" End If ' Iterate through the cells of a row. For i = 0 To numcells - 1 ' Create a new cell and add it to the HtmlTableRow ' Cells collection. cell = New HtmlTableCell() cell.Controls.Add(New LiteralControl("row " & _ j.ToString() & _ ", cell " & _ i.ToString())) row.Cells.Add(cell) Next i ' Add the row to the HtmlTable Rows collection. Table1.Rows.Add(row) Next j End Sub </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3>HtmlTable Example</h3> <table id="Table1" CellPadding="5" CellSpacing="0" Border="1" BorderColor="black" runat="server"/> <hr> Select the number of rows and columns to create: <br><br> Table rows: <select id="Select1" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> Table cells: <select id="Select2" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> <br><br> <input type="submit" value="Generate Table" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Get the number of rows and columns selected by the user. int numrows = Convert.ToInt32(Select1.Value); int numcells = Convert.ToInt32(Select2.Value); // Iterate through the rows. for (int j = 0; j < numrows; j++) { // Create a new row and add it to the Rows collection. HtmlTableRow row = new HtmlTableRow(); // Provide a different background color for alternating rows. if (j % 2 == 1) row.BgColor = "Gray"; // Iterate through the cells of a row. for (int i = 0; i < numcells; i++) { // Create a new cell and add it to the HtmlTableRow // Cells collection. HtmlTableCell cell = new HtmlTableCell(); cell.Controls.Add(new LiteralControl("row " + j.ToString() + ", cell " + i.ToString())); row.Cells.Add(cell); } // Add the row to the HtmlTable Rows collection. Table1.Rows.Add(row); } } </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3>HtmlTable Example</h3> <table id="Table1" CellPadding="5" CellSpacing="0" Border="1" BorderColor="black" runat="server"/> <hr> Select the number of rows and columns to create: <br><br> Table rows: <select id="Select1" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> Table cells: <select id="Select2" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> <br><br> <input type="submit" value="Generate Table" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" %> <script runat="server"> function Page_Load(sender : Object, e : EventArgs) { // Get the number of rows and columns selected by the user. var numrows : int = Convert.ToInt32(Select1.Value); var numcells : int = Convert.ToInt32(Select2.Value); // Iterate through the rows. for (var j : int = 0; j < numrows; j++) { // Create a new row and add it to the Rows collection. var row : HtmlTableRow = new HtmlTableRow(); // Provide a different background color for alternating rows. if (j%2 == 1) row.BgColor="Gray"; // Iterate through the cells of a row. for (var i : int = 0; i < numcells; i++) { // Create a new cell and add it to the HtmlTableRow // Cells collection. var cell : HtmlTableCell = new HtmlTableCell(); cell.Controls.Add(new LiteralControl("row " + j.ToString() + ", cell " + i.ToString())); row.Cells.Add(cell); } // Add the row to the HtmlTable Rows collection. Table1.Rows.Add(row); } } </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3>HtmlTable Example</h3> <table id="Table1" CellPadding="5" CellSpacing="0" Border="1" BorderColor="black" runat="server"/> <hr> Select the number of rows and columns to create: <br><br> Table rows: <select id="Select1" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> Table cells: <select id="Select2" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> <br><br> <input type="submit" value="Generate Table" runat="server"/> </form> </body> </html>


System.Web.UI.Control
System.Web.UI.HtmlControls.HtmlControl
System.Web.UI.HtmlControls.HtmlContainerControl
System.Web.UI.HtmlControls.HtmlTable


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTable コンストラクタ
アセンブリ: System.Web (system.web.dll 内)



HtmlTable コントロールの新しいインスタンスをプログラムから作成して Web ページに配置する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <script runat="server" > Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create an instance of an HtmlTable control. Dim table As HtmlTable = New HtmlTable() table.Border = 1 table.CellPadding = 3 ' Populate the HtmlTable control by adding rows to it. Dim rowcount As Integer Dim cellcount As Integer ' Create the rows of the table. For rowcount = 0 To 4 ' Create a new HtmlTableRow control. Dim row As HtmlTableRow = New HtmlTableRow() ' Add cells to the HtmlTableRow control. For cellcount = 0 To 3 ' Define a new HtmlTableCell control. Dim cell As HtmlTableCell ' Create table header cells for the first row. If rowcount <= 0 Then cell = New HtmlTableCell("th") Else cell = New HtmlTableCell() End If ' Create the text for the cell. cell.Controls.Add(New LiteralControl( _ "row " & rowcount.ToString() & ", " & _ "column " & cellcount.ToString())) ' Add the cell to the HtmlTableRow Cells collection. row.Cells.Add(cell) Next cellcount ' Add the row to the HtmlTable Rows collection. table.Rows.Add(row) Next rowcount ' Add the control to the Controls collection of the ' PlaceHolder control. Place.Controls.Clear() Place.Controls.Add(table) End Sub </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3> HtmlTable Example </h3> <asp:PlaceHolder id="Place" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <script runat="server" > void Page_Load(Object sender, EventArgs e) { // Create an instance of an HtmlTable control. HtmlTable table = new HtmlTable(); table.Border = 1; table.CellPadding = 3; // Populate the HtmlTable control by adding rows to it. for (int rowcount = 0; rowcount < 5; rowcount++) { // Create a new HtmlTableRow control. HtmlTableRow row = new HtmlTableRow(); // Add cells to the HtmlTableRow control. for (int cellcount = 0; cellcount < 4; cellcount++) { // Define a new HtmlTableCell control. HtmlTableCell cell; // Create table header cells for the first row. if (rowcount <= 0) { cell = new HtmlTableCell("th"); } else { cell = new HtmlTableCell(); } // Create the text for the cell. cell.Controls.Add(new LiteralControl( "row " + rowcount.ToString() + ", " + "column " + cellcount.ToString())); // Add the cell to the HtmlTableRow Cells collection. row.Cells.Add(cell); } // Add the row to the HtmlTable Rows collection. table.Rows.Add(row); } // Add the control to the Controls collection of the // PlaceHolder control. Place.Controls.Clear(); Place.Controls.Add(table); } </script> <html> <head> <title>HtmlTable Example</title> </head> <body> <form runat="server"> <h3> HtmlTable Example </h3> <asp:PlaceHolder id="Place" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTable プロパティ



関連項目
HtmlTable クラスSystem.Web.UI.HtmlControls 名前空間
HtmlContainerControl クラス
HtmlTableCell
HtmlTableCellCollection
HtmlTableRow
HtmlTableRowCollection
その他の技術情報
HTML サーバー コントロールHtmlTable メソッド



関連項目
HtmlTable クラスSystem.Web.UI.HtmlControls 名前空間
HtmlContainerControl クラス
HtmlTableCell
HtmlTableCellCollection
HtmlTableRow
HtmlTableRowCollection
その他の技術情報
HTML サーバー コントロールHtmlTable メンバ
サーバー上で HTML <table> 要素に、プログラムでアクセスできるようにします。
HtmlTable データ型で公開されるメンバを以下の表に示します。






名前 | 説明 | |
---|---|---|
![]() | DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。(Control から継承されます。) |
![]() | Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。(Control から継承されます。) |
![]() | Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。(Control から継承されます。) |
![]() | Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。(Control から継承されます。) |
![]() | PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。(Control から継承されます。) |
![]() | Unload | サーバー コントロールがメモリからアンロードされると発生します。(Control から継承されます。) |

関連項目
HtmlTable クラスSystem.Web.UI.HtmlControls 名前空間
HtmlContainerControl クラス
HtmlTableCell
HtmlTableCellCollection
HtmlTableRow
HtmlTableRowCollection
その他の技術情報
HTML サーバー コントロールWeblioに収録されているすべての辞書からHtmlTableを検索する場合は、下記のリンクをクリックしてください。

- HtmlTableのページへのリンク