I am deleting a row from gridview for which i have used gridview\'s default delete command field. On clicking, the gridview row deleting command gets fired and the selected row
Try this.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (DataControlFieldCell cell in e.Row.Cells)
{
foreach (Control control in cell.Controls)
{
// Choose between Button, ImageButton and LinkButton.
// as my ButtonType="Button".
Button button = control as Button;
if (button != null && button.CommandName == "Delete")
{
string script = "if(confirm('Are you sure to delete?')) __doPostBack('{0}','{1}${2}'); else return false;";
string clickEvent = String.Format(
script,
GridView1.ClientID,
button.CommandName,
button.CommandArgument);
button.Attributes.Add("onclick", clickEvent);
break;
}
}
}
}
}
Much more dirty than I originally anticipated. Better to use a asp:TemplateField
:)
Please note that my ButtonType="Button"