Tableheader

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
I have a function with an array, where i am trying to set the header text in a dynamically created table.

VB.NET:
Dim Headers() As String={"One", "Two", "Three"} 
        For Header As Integer = 1 To 3 
            thc = New TableHeaderCell 
  
            For Each hdr As String In Headers 
                thc.Text = hdr 
            Next 
            thr.Cells.Add(thc) 
            tbl.Rows.Add(thr) 
        Next

This doesnt seem to display any of the values contained in the array, yet if i change the line
thc.Text = hdr
to
thc.Text = Header
it displays a value in the header (in other words the code executes as expected and create table headers)? I cant figure out why the array doesnt work in the same manner?



thanks
 
Hi,

It looks like you have got your code a bit mixed up. You also forget the Dim statement on the thc variable. Try this instead:-

VB.NET:
Dim Headers() As String = {"One", "Two", "Three"}
For Each HeaderString In Headers
  Dim thc = New TableHeaderCell
  thc.Text = HeaderString
  thr.Cells.Add(thc)
Next
tbl.Rows.Add(thr)
Cheers,

Ian
 
Back
Top