Dear All,
I am trying to delete a row in the GridView with an ImageButton Link. By clicking the button, the GridView row is set with a backColor = "Red" and with delete confirmation window. On Cancel, the background color is removed, but When I confirm the deletion, the row is not deleted. I use the following code:
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:ImageButton ID="deleteImageLink" runat="Server" ImageUrl="~/images/Delete.gif" CommandName="Delete">
</asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
------------------------------------------------------
<asp:ButtonField CommandName="Delete" ButtonType="Image" ImageUrl="~/images/delete.gif" />
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton deleteButton = (ImageButton)e.Row.FindControl("deleteImageLink");
deleteButton.Attributes.Add("onclick", "this.originalcolor=this.style.backgroundColor;" + " this.parentNode.parentNode.style.backgroundColor='Red'; if (confirm('Are you sure you want to delete this RED row?')) return true; else {this.parentNode.parentNode.style.backgroundColor=this.originalcolor; return true;}");
}
}
The bellow code deletes the row, but the without setting the background color on the row prior deletion:
ImageButton deleteButton = (ImageButton)e.Row.FindControl("deleteImageLink");
deleteButton.OnClientClick = "if (confirm('Are you sure you want to delete this user account?') == false) return false;";
Many thanks in advance