Create a table via code-behind

Results 1 to 2 of 2

Thread: Create a table via code-behind

  1. #1
    Join Date
    Dec 1969

    Default Create a table via code-behind

    I&#039;m trying to create a table with rows and columns via code-behind. My end goal is to embed other controls in the table but for right now I&#039;d be happy just to get the table to display. I&#039;m using the webforms table control and some code I&#039;ve listed below. The problem is that I never see the table and I&#039;m not sure why. <BR><BR>Questions: Is this the right control to use when I want to programtically create rows and columns at run time based on some results returned from a database read and then build a row of controls?<BR><BR>Based on the code behind listed below what am I missing that would prevent the table from being displayed. Thanks!<BR><BR><BR><BR> Dim tblTable As Table<BR> Dim tblRow As TableRow<BR> Dim tblCell As TableCell<BR><BR> tblTable = New Table<BR> tblRow = New TableRow<BR> tblTable.GridLines = GridLines.Both<BR> tblCell = New TableCell<BR> tblTable.BorderStyle = BorderStyle.Groove<BR> tblTable.BorderColor = Color.White<BR> tblTable.BorderWidth = Unit.Pixel(3)<BR> tblCell.Text = "This text would appear in the first column."<BR> tblRow.Cells.Add(tblCell)<BR> tblCell = New TableCell<BR> tblCell.Text = "This text would appear in the second column."<BR> tblRow.Cells.Add(tblCell)<BR> tblTable.Rows.Add(tblRow)<BR> Form1.Controls.Add(tblTable)

  2. #2
    Join Date
    Dec 1969

    Default RE: Create a table via code-behind

    Do you get any errors? Do you have a valid reference to Form1? Did you try Page.Controls.Add(tblTable)?

Posting Permissions

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