create html table dynamically


/ Published in: C#
Save to your folder(s)

create html table dynamically


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.