asp:DataGrid Client-side Confirm Delete

I use this helpful article to come up with a nice client-side delete when deleting
a row from an ASP.Net datagrid.

http://authors.aspalliance.com/aldotnet/examples/cd.aspx

My resulting code:

private void _dgProjectTypes_ItemCreated(object sender,
System.Web.UI.WebControls.
DataGridItemEventArgs
e)
{
switch( e.Item.ItemType
)
{

case ListItemType.Item:
case ListItemType.AlternatingItem:
case ListItemType.EditItem:

TableCell myTableCell = e.Item.Cells[2];
Button myDeleteButton = (Button)myTableCell.Controls[0];
myDeleteButton.Attributes.Add(@”onclick”, @”return
confirm(‘Are you sure you want to delete this Project Type?’);”
);

break;
}

}

Proudly powered by WordPress | Theme: Code Blog by Crimson Themes.