Raising ItemCommand event from a DataGrid nested in a DataList

  • Thread starter Thread starter Matthew
  • Start date Start date
M

Matthew

I have a DataGrid nested within a DataList. The DataGrid generates
LinkButtons with specific CommandName values. I cannot figure out how
to trap this event. I need to know which DataGrid LinkButton was
selected.

Thanks in advance.
 
give the link button on the datagrid a command name Like
CommandName="DeleteClick" and then in the itemcommand event for the datagrid
check for the command name like
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgWires.ItemCommand

If e.CommandName="DeleteClick" Then

End If

End Sub

HTH
 
The issue is that DataGrid is nested within a DataList.
Therefore when you try to hook the event up (In InitializeComponent())
using

this.instancesGrid.ItemCommand += new
DataGridCommandEventHandler(InstancesGrid_ItemCommand);

you'll get a "Object reference not set to an instance of an object."
error. That's because the grid doesn't exist yet. Therefore, I've
tried to wait to hook up the event until the parent DataList
ItemDataBound event.

In the ItemDataBound event I had this code:
((DataGrid)e.Item.FindControl("instancesGrid")).ItemCommand += new
DataGridCommandEventHandler(InstancesGrid_ItemCommand);

Although that won't cause an error to be raised, it will not call the
method I'm trying to call (InstancesGrid_ItemCommand). It does call
some event because I can see the page postback, but I'm not sure what
event that is.

Thanks for your help.
 
Back
Top