Posted By

hairajeshk on 10/09/10


Tagged

table html dynamically


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

sharathreddyp
Tyster


create html table dynamically


 / Published in: C#
 

create html table dynamically

  1. Dim i As Integer
  2. Dim j As Integer
  3. Dim row As HtmlTableRow
  4. Dim cell As HtmlTableCell
  5.  
  6. ' Get the number of rows and columns selected by the user.
  7. Dim numrows As Integer = CInt(Select1.Value)
  8. Dim numcells As Integer = CInt(Select2.Value)
  9.  
  10. ' Iterate through the rows.
  11. For j = 0 to numrows - 1
  12.  
  13. ' Create a new row and add it to the Rows collection.
  14. row = New HtmlTableRow()
  15.  
  16. ' Provide a different background color for alternating rows.
  17. If (j Mod 2) = 1 Then
  18. row.BgColor="Gainsboro"
  19. End If
  20.  
  21. ' Iterate through the cells of a row.
  22. For i = 0 to numcells - 1
  23.  
  24. ' Create a new cell and add it to the Cells collection.
  25. cell = New HtmlTableCell()
  26. cell.Controls.Add(new LiteralControl("row " & _
  27. j.ToString() & _
  28. ", cell " & _
  29. i.ToString()))
  30. row.Cells.Add(cell)
  31.  
  32. Next i
  33.  
  34. Table1.Rows.Add(row)
  35.  
  36. Next j

Report this snippet  

You need to login to post a comment.