Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create an array of HtmlTableCell variables? 1

Status
Not open for further replies.

dpdoug

Programmer
Nov 27, 2002
455
0
0
US
I have come across a situation where it may be an advantage to use HtmlTableRow and HtmlTableCell. However, just a table with 7 rows and 6 columns can create a need to have 42 HtmlTableCells. And "Explicit Initialization" is not permitted with these objects. In other words you can't do this:

Code:
Dim C1, C2, C3, C4 As As New HtmlTableCell()

It has to be like this:

Code:
Dim C1 As New HtmlTableCell(), C2 As New HtmlTableCell()
Dim C3 As New HtmlTableCell(), C4 As New HtmlTableCell()

So can you imagine what it would be like doing 6 tables like this?

My question is, is there any way to create an array of this type of variable and then loop through it?

Otherwise, it would be easier to just create strings of HTML and loop through them and return a table to populate a label or a Session variable. I did this a lot when I programmed in classic ASP.

 
This is an example from the MSDN Library:

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<script runat="server" >

Sub Page_Load(sender As Object, e As EventArgs)

' Create the HtmlTable control.
Dim table As HtmlTable = New HtmlTable()
table.Border = 1
table.CellPadding = 3

' Populate the HtmlTable control.

Dim rowcount As Integer
Dim cellcount As Integer

' Create the rows of the table.
For rowcount=0 to 4

Dim row As HtmlTableRow = New HtmlTableRow()

' Create the cells of a row.
For cellcount=0 to 3

Dim cell As HtmlTableCell

' Create table header cells for 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 Cells collection of a row.
row.Cells.Add(cell)

Next cellcount

' Add the row to the Rows collection of the table.
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>

<body>

<form runat="server">

<h3> HtmlTable Example </h3>

<asp:placeHolder id="Place" runat="server"/>

</form>

</body>
</html>
 
Thanks for the tip, I'll give it a try!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top