Richard,
Firstly, I am assuming you have set the DataKeyNames property on the gridview and the data source DeleteCommand and DeleteParameters correctly?
I tend to put this code in the RowDataBound event of the grid, this gives me the opportunity to personalise the message using something along the following lines.
protected void GridViewTest_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Edit ||
e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit))
{
}
else
{
LinkButton DeleteButton = (LinkButton)e.Row.Cells[1].Controls[0];
DataRow MyDataRow = (DataRow)((DataRowView)e.Row.DataItem).Row;
if (DeleteButton != null && MyDataRow != null)
{
DeleteButton.OnClientClick = "return confirm('" +
string.Format((string)base.GetLocalResourceObject("String.RecordDeletePrompt"),
((string)MyDataRow["Name"]).Replace("'", @"\'")) + "');";
}
}
}
}
}
The (string)base.GetLocalResourceObject("String.RecordDeletePrompt") is loading a string from an embedded resource.
You are about to delete {0} from the table
Regards
Neil