Saturday, January 29, 2011

How To Add JavaScript Delete Confirmation in GridView "Delete" Command Button dynamically?

if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].HasControls())
{
LinkButton lnkbtnDelete = ((LinkButton)e.Row.Cells[1].Controls[0]);
lnkbtnDelete.Attributes.Add("onclick", "return confirm('Do you want to Delete?');");
}
}

Note:
1. The Cell starts with 0 Index.
2. The line "if (e.Row.Cells[1].HasControls())" is to check, if the control is exists or not. This will be useful, when Edit Command Button is used along with Delete Command Button.

No comments:

Post a Comment

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...