Dynamically Building a Table

  • Thread starter Thread starter brian
  • Start date Start date
B

brian

Hello, I have spen hours trying to find information on
dynamically building a table from an array.

What I need:
I have an array pulling file paths from a directory using
a For Next Loop. F is the file. For every instance of F
I would like the file path put into the table. The table
is just a single column table.

I have looked at the Table class on msdn and that hasn't
helped me much. Can someone show me an example or maybe
lead me somewhere besides msdn for information.

Thanks
 
Hi

Try this way:

Response.Write("<TABLE>")
Response.Write("<TR>")
foreach(file in files)
{
Response.Write("<TD>")
Response.Write(file)
Response.Write("</TD>")

}
Response.Write("</TR>")
Response.Write("</TABLE>")

HTH

Ravikanth[MVP]
 
That is certainly one way.

Alternatively, if you want to use a table control, then you'd need to:

declare (or add) a table control
then create table rows
for each table row, you'd need to create, and add, a table cell
for each table cell, you'd need to add a literal control containing the text
that you want.

Cheers
Ken

: Hi
:
: Try this way:
:
: Response.Write("<TABLE>")
: Response.Write("<TR>")
: foreach(file in files)
: {
: Response.Write("<TD>")
: Response.Write(file)
: Response.Write("</TD>")
:
: }
: Response.Write("</TR>")
: Response.Write("</TABLE>")
:
: HTH
:
: Ravikanth[MVP]
:
:
: >-----Original Message-----
: >Hello, I have spen hours trying to find information on
: >dynamically building a table from an array.
: >
: >What I need:
: >I have an array pulling file paths from a directory
: using
: >a For Next Loop. F is the file. For every instance of
: F
: >I would like the file path put into the table. The
: table
: >is just a single column table.
: >
: >I have looked at the Table class on msdn and that hasn't
: >helped me much. Can someone show me an example or maybe
: >lead me somewhere besides msdn for information.
: >
: >Thanks
: >.
: >
 
Try this way:
Response.Write("<TABLE>")
Response.Write("<TR>")
foreach(file in files)

1. Using Response.Write in an ASPX page is not object-oriented.
2. This example seems to be using a combination of VB.Net and C# - it would
never work as it stands

Brian didn't specify what kind of table he wanted to use (HtmlTable or Table
Web Server Control). I will use the one with the smallest footprint
(HtmlTable) for this explanation. The principle would be the same for a
Table Web Server Control.

The easiest thing to do would be to put an HtmlTable Control on the page.
Then you can add rows and cells to it. A row is an HtmlTableRow object, and
it is added to the table's Rows Collection. Once you add a row, you can add
cells. The HtmlTableRow class has a Collection of HtmlTableCell objects. So,
assuming that you've put an HtmlTable control on your page, made it runat
server, and assigned an ID to it, all you need to do is loop through your
array, and

1. Add an HtmlTableRow to the Rows collection of the table
2. Add an HtmlTableCell to the Cells collection of the row
3. Assign the value from the array to the InnerHtml or InnerText property of
the cell

- for each element in the array.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.
 
Hello, I have spen hours trying to find information on
dynamically building a table from an array.

What I need:
I have an array pulling file paths from a directory using
a For Next Loop. F is the file. For every instance of F
I would like the file path put into the table. The table
is just a single column table.

I have looked at the Table class on msdn and that hasn't
helped me much. Can someone show me an example or maybe
lead me somewhere besides msdn for information.


Dim tblRow as TableRow
Dim tblCell as TableCel
Dim tblTest as Table = New Table()

For i = 0 to somebound
tblRow = New TableRow()
tblCell = new TableCell()

tblCell.text = "Some Junk Here"
tblRow.Cells.Add(tblCell)
tblTest.Rows.add(tblRow)
Next
 
Back
Top