Button in dynamic table cell

  • Thread starter Thread starter Owen Mortensen
  • Start date Start date
O

Owen Mortensen

How do I get a dynamically created button control to appear in a dynamically
created table cell?

Here's what I've tried:


While objDR1.Read()
Dim objButton As New Button
Dim objTableRow As New TableRow
Dim objTableCell As New TableCell
Dim strURL As String = objDR1("URL").ToString()

objButton.Text = "edit"
objButton.Visible = True
objButton.Width = New Unit(60)
objButton.Height = New Unit(20)

AddHandler objButton.Click, AddressOf DynamicButtonClick

objTableCell.Controls.Add(objButton)
objTableCell.Text = objMember.AuthorizeGetPageRoles(strURL).Replace(",",
"<br>")
objTableRow.Cells.Add(objTableCell)
objTableCell = New TableCell
objTableCell.Text = objDR1("DisplayName").ToString()
objTableRow.Cells.Add(objTableCell)
objTableCell = New TableCell
objTableCell.Text = strURL
objTableRow.Cells.Add(objTableCell)
tblMenuSecurity.Rows.Add(objTableRow)
End While

This does not work: the buttons do not show up in the table cells (in fact,
they don't show up at all, anywhere).

Ideas?

TIA,
Owen
 
OK, I feel silly now. Note that in addition to adding to the controls
collection of the table cell, I also try to set the text property. This
must clear any other events that tried to set text in the cell. By removing
the objTableCell.Text = ... line of code, the buttons show up and operate as
expected.

Cheers,
Owen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top