How can I customize automatically generated command button, e.g. Delete
?
I want to add a client confirmation on deleting and in the same moment I want this
You can probably do it by implementing the PreRender
event for the grid.
Here is some basic psuedo code:
protected void yourGrid_PreRender(object sender, EventArgs e)
{
GridView grd = (GridView)(sender);
// iterate through all your rows and look for the button
// make sure to add code to verify your rows, columns, and control bounds are valid
for (int rowIndex = 0; rowIndex < grd.Rows.Count; rowIndex++)
{
LinkButton btn = grd.Rows[rowIndex].Cells[deleteButtonColumnIndex].Controls[0] as LinkButton;
// Here you have access to the button so change it to do what you need.
btn.OnClientClick = string.Format("return confirm('{0}?')", btn.Text);
}
}
Also if you want it baked in you will probably need to extend the GridView and implement your own code. See the following thread:
http://forums.asp.net/p/1396268/3011988.aspx#3011988