Link to home
Start Free TrialLog in
Avatar of rogerfg7
rogerfg7

asked on

Linking ItemCommand in Datagrid embedded in DataList

We have a DataGrid embedded in a DataList.  The DataList can display mulitple records (if present) and the DataGrid displays children records of the parent.  We want to be able to provide  delete function for the child records and have added the following column to the <Columns>

<asp:TemplateColumn HeaderText="Delete" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="40px">
  <ItemTemplate>
    <asp:ImageButton ID="btnDelete" ImageUrl="~/images/delete.gif" Runat="server" AlternateText="Delete" CommandName="Delete" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"UserID")+","+DataBinder.Eval(Container.DataItem,"CustomerID")+","+DataBinder.Eval(Container.DataItem,"SubscriptionID")%>'>
    </asp:ImageButton>
  </ItemTemplate>
</asp:TemplateColumn>

The DataGrid does not display in the designer, so we are attempting to bind the ItemCommand event handler in the DataList ItemDataBound event

BulkSubscriptionController bc = new BulkSubscriptionController ();

DataGrid grd = (DataGrid)e.Item .FindControl ("grdSubscribedUsers");
grd.DataSource = bc.GetBulkSubscriptionUsers (bsi.CustomerID,bsi.SubscriptionID);
grd.DataBind ();
grd.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grdSubscribedUsers_ItemCommand);

However, the grdSubscribedUsers_ItemCommand does not fire on clicking the btnDelete image, although the form does PostBack.

Any assistance would be gratefully appreciated

Many thanks

Roger Graham
Avatar of digitalZo
digitalZo
Flag of India image

Can you post the code for ItemCommand where you have defined the 'Delete' CommandName?
ASKER CERTIFIED SOLUTION
Avatar of tovvenki
tovvenki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rogerfg7
rogerfg7

ASKER

Assigning the OnDeleteCommand in the HTML <asp:DataGrid> worked.   Many thanks.  But why does assigning this in code not work?