HtmlTableCellCollection.Insert(Int32, HtmlTableCell) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 HtmlTableCell 개체를 HtmlTableCellCollection 컬렉션의 지정된 인덱스 위치에 추가합니다.
public:
void Insert(int index, System::Web::UI::HtmlControls::HtmlTableCell ^ cell);
public void Insert (int index, System.Web.UI.HtmlControls.HtmlTableCell cell);
member this.Insert : int * System.Web.UI.HtmlControls.HtmlTableCell -> unit
Public Sub Insert (index As Integer, cell As HtmlTableCell)
매개 변수
- index
- Int32
HtmlTableCellCollection를 추가할 HtmlTableCell의 위치입니다.
- cell
- HtmlTableCell
HtmlTableCell에 추가할 HtmlTableCellCollection입니다.
예제
다음 코드 예제를 사용 하는 방법에 설명 합니다 Insert 동적으로 나타내는 테이블의 셀을 삽입 하는 방법은 HtmlTableCell 개체에 HtmlTableCellCollection 컬렉션입니다.
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 Cells collection.
HtmlTableCell cell = new HtmlTableCell();
cell.Controls.Add(new LiteralControl("row " +
j.ToString() +
", cell " +
i.ToString()));
row.Cells.Insert(i, cell);
}
Table1.Rows.Insert(j, row);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTableCellCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlTableCellCollection Example</h3>
<table id="Table1"
style="border-width:1; border-color:Black; padding:5"
cellspacing="0"
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="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 and add it to the Rows collection.
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 Cells collection.
cell = New HtmlTableCell()
cell.Controls.Add(New LiteralControl("row " & _
j.ToString() & _
", cell " & _
i.ToString()))
row.Cells.Insert(i, cell)
Next i
Table1.Rows.Insert(j, row)
Next j
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTableCellCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlTableCellCollection Example</h3>
<table id="Table1"
style="border-width:1; border-color:Black; padding:5"
cellspacing="0"
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>
설명
사용 하 여를 Insert 지정 된 추가 하는 방법 HtmlTableCell 개체는 HtmlTableCellCollection 컬렉션의 지정 된 인덱스입니다. 단순히 추가 하려는 경우는 HtmlTableCell 개체를 사용 하 여 컬렉션의 끝에는 Add 메서드.