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-HorizontalAlig n="Center" ItemStyle-HorizontalAlign= "Center" ItemStyle-Width="40px">
<ItemTemplate>
<asp:ImageButton ID="btnDelete" ImageUrl="~/images/delete. gif" Runat="server" AlternateText="Delete" CommandName="Delete" CommandArgument='<%#DataBi nder.Eval( Container. DataItem," UserID")+" ,"+DataBin der.Eval(C ontainer.D ataItem,"C ustomerID" )+","+Data Binder.Eva l(Containe r.DataItem ,"Subscrip tionID")%> '>
</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.GetBulkSubscriptionUser s (bsi.CustomerID,bsi.Subscr iptionID);
grd.DataBind ();
grd.ItemCommand += new System.Web.UI.WebControls. DataGridCo mmandEvent Handler(th is.grdSubs cribedUser s_ItemComm and);
However, the grdSubscribedUsers_ItemCom mand does not fire on clicking the btnDelete image, although the form does PostBack.
Any assistance would be gratefully appreciated
Many thanks
Roger Graham
<asp:TemplateColumn HeaderText="Delete" HeaderStyle-HorizontalAlig
<ItemTemplate>
<asp:ImageButton ID="btnDelete" ImageUrl="~/images/delete.
</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
DataGrid grd = (DataGrid)e.Item .FindControl ("grdSubscribedUsers");
grd.DataSource = bc.GetBulkSubscriptionUser
grd.DataBind ();
grd.ItemCommand += new System.Web.UI.WebControls.
However, the grdSubscribedUsers_ItemCom
Any assistance would be gratefully appreciated
Many thanks
Roger Graham
Can you post the code for ItemCommand where you have defined the 'Delete' CommandName?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Assigning the OnDeleteCommand in the HTML <asp:DataGrid> worked. Many thanks. But why does assigning this in code not work?