I want to fire the Delete Command in Datalist Control .. but it is not firing .. Help please ..
this is my code :
protected void DeleteCommand(object source, DataListCommandEventArgs e)
{
Label2.Text = "hello";
}
and This is my html code :
<asp:DataList ID="DLImages" runat="server" BorderStyle="None"
DataKeyField="fId" RepeatColumns="4"
RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False"
OnDeleteCommand="DeleteCommand"
onitemdatabound="DLImages_ItemDataBound">
<ItemTemplate>
<asp:ImageButton ID="IBDelete" runat="server" BorderStyle="None" CommandName="Delete" ImageUrl="~/Dashboard/Images/dldelete.png" />
</ItemTemplate>
</asp:DataList>
..
Your code looks like OK to me. It should fire the
DeleteCommand.But the problem is that I am sure you are binding the Datalist in your
page_load event, but not underIf(!IsPostBack) condition.What happens when you hit Delete button is yourpage_loadevent fires before yourDeleteCommandand it rebinds theDataListand your event is lostYour page_load event code should look like…