Delete Confirmation

  • Thread starter Thread starter AJMAL YAZDANI
  • Start date Start date
A

AJMAL YAZDANI

Hello All,

In my GridView, I am using "BoundFiled" for "Delete" functionality instead of "ItemTemplate".

Now, I want a "Delete Confirmation" with Javascript.

What I have to do.

Regards,

Ajmal
 
In my GridView, I am using "BoundFiled" for "Delete" functionality instead
of "ItemTemplate".

Now, I want a "Delete Confirmation" with Javascript.

What I have to do.

In the ItemDataBound event, add the javascript code to your boundfield:

private void myGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
string script = "javascript:return confirm('Are you sure?')";

if (e.Item.ItemType!=ListItemType.Header &&
e.Item.ItemType!=ListItemType.Footer)
{
ImageButton imgButton = (ImageButton)e.Item.Cells[0].Controls[1];
if (imgButton.CommandName == "Delete")
{
imgButton.Attributes["onclick"] = script;
}
}
}

Obviously, in the preceding code, you will have to replace the
Cells[0].Controls[1] with the location of your actual control, and if it is
not an ImageButton you will also have to change the type also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top