Professional Web Applications Themes

Dynamically Building a Table - ASP.NET General

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...

  1. #1

    Default Dynamically Building a Table

    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
    brian Guest

  2. #2

    Default Dynamically Building a Table

    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]

     
    using 

    table 
    Ravikanth[MVP] Guest

  3. #3

    Default Re: Dynamically Building a Table

    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

    "Ravikanth[MVP]" <com> wrote in message
    news:0d6001c36bd8$5f814080$gbl...
    : 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
    : >.
    : >


    Ken Guest

  4. #4

    Default Re: Dynamically Building a Table

    > Try this way: 

    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.

    "Ravikanth[MVP]" <com> wrote in message
    news:0d6001c36bd8$5f814080$gbl... 
    > using 
    > F 
    > table [/ref]


    Kevin Guest

  5. #5

    Default Re: Dynamically Building a Table

    "brian" <com> wrote in news:0d2901c36bd6$20166da0
    $gbl:
     


    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


    --
    Lucas Tam (com)
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
    Lucas Guest

Similar Threads

  1. Dynamically Building Controls in ASP.net
    By D.Dark in forum ASP.NET Building Controls
    Replies: 2
    Last Post: November 20th, 02:36 PM
  2. dynamically building template columns
    By jonefer in forum ASP.NET Building Controls
    Replies: 4
    Last Post: May 26th, 06:08 PM
  3. Building Query criteria dynamically based on Form inputs
    By Beards247 in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: August 2nd, 06:59 AM
  4. Dynamically Building Property Values for Designer
    By paul reed in forum ASP.NET Building Controls
    Replies: 8
    Last Post: February 16th, 09:15 PM
  5. Dynamically building up a WHERE clause
    By Beverley in forum Microsoft SQL / MS SQL Server
    Replies: 2
    Last Post: July 17th, 11:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139