Dynamic Datagrid Creation - ItemCommand event not firing

P

PD

I am generating a dynamic datagrid that gets assigned to a cell within
the parent grid. Here's the html:

<asp:DataGrid id="dgPositions" runat="server" Width="710"
CellPadding="3" HeaderStyle-Font-Bold="True" CssClass="inputfields"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn></asp:TemplateColumn>
</Columns>
</asp:DataGrid>

I have a custom control within the child grid that inherits from the
ImageButton control:

With cb
.ToolTip = "Remove"
.CausesValidation = False
.ImageUrl = "images/delete_s1.gif"
.Message = "Are you sure you want to delete
this?"
.ID = "btnRemove"
.AlternateText = "Remove"
.CommandName = "Delete"
End With
container.Controls.Add(cb)

The child grid is constructed within the dgPositions_ItemDataBound
function of the parent grid.

dgNewGrid.HeaderStyle.Font.Bold = True
dgNewGrid.CellPadding = 3
dgNewGrid.CssClass = "inputfields"
dgNewGrid.AutoGenerateColumns = False
dgNewGrid.ID = "gridPositions"
AddHandler dgNewGrid.ItemCommand, AddressOf
dgPositions_ItemCommand2
dgi.Cells(0).Controls.Add(dgNewGrid)


I want the dgPositions_ItemCommand2 to kick off when the user clicks
on the custom control (cb) above. The code to
dgPositions_ItemCommand2:

Public Sub dgPositions_ItemCommand2(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs)
Try
If e.CommandName = "Delete" Then
Response.Write("Test")
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub

I have not been successful in getting the dgPositions_ItemCommand2
code to kick off. Any thoughts/suggestions would be greatly
appreciated!!

Thanks,
Patrick
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top