responding to an event from a dynamically created control


Joined
Sep 8, 2008
Messages
1
Reaction score
0
I have created a table dynamically, and I create in it several LinkedButton controls.
I register the Click event with my handling method, but it never gets called.
Can anyone help with that?
I would really appreciate it. Thanks.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
'header row
columnHeaders = New CRowData()
columnHeaders.arrData(0)._textData = "Zero"
columnHeaders.arrData(1)._textData = "Column Uno"

'initial row of data
Dim row1 As New CRowData()
row1.arrData(0)._textData = "RowUno"
row1.arrData(1)._textData = "SampleData"

rows = New List(Of CRowData)
rows.Add(row1)

Session("columnHeaders") = columnHeaders
Session("rows") = rows

SetupTable()
End If

End Sub

Sub SetupTable()
Table1.Rows.Clear()

'add header cells
Dim rowHeader As New TableRow()
For i As Integer = 0 To columnHeaders.arrData.Count - 1
Dim tCell As New TableHeaderCell()
tCell.Text = columnHeaders.arrData(i)._textData
rowHeader.Cells.Add(tCell)
Next

'add rows to the table
Table1.Rows.Add(rowHeader)

For indexRow As Integer = 0 To rows.Count - 1
'add first row cell (row title)
Dim thCell As New TableHeaderCell()
thCell.Text = "text"

Dim lb As New LinkButton()
lb.EnableViewState = True
lb.ID = indexRow.ToString
lb.PostBackUrl = "default.aspx"
lb.Text = rows(indexRow).arrData(0)._textData + lb.ID
AddHandler lb.Click, AddressOf btnEdit_Click
thCell.Controls.Add(lb)

Dim row As New TableRow()
row.Cells.Add(thCell)
'add the remaining cells
For indexColumn As Integer = 1 To columnHeaders.arrData.Count - 1
Dim tCell As New TableCell()
tCell.Text = rows(indexRow).arrData(indexColumn)._textData
row.Cells.Add(tCell)
Next
Table1.Rows.Add(row)
Next
End Sub

Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
columnHeaders = Session("columnHeaders")
rows = Session("rows")

'cycle thru the row headers and find the sender

For index As Integer = 0 To rows.Count - 1
Dim lb As LinkButton = CType(sender, LinkButton)
If lb.UniqueID = CType(Table1.Rows(index).Cells(0).Controls(0), LinkButton).UniqueID Then
lb.Text = "Bingo"
End If
Next

End Sub
 
Ad

Advertisements


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

Top