Confirm a delete in a Datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?QXJuZQ==?=, Apr 28, 2005.

  1. I have a delete column in a datagird.
    I would like to execute
    cmdDelete.Attributes.Add("onclick", "return confirm('Delete this record?');")
    somewhere.
    Where is the right place to put this code?
     
    =?Utf-8?B?QXJuZQ==?=, Apr 28, 2005
    #1
    1. Advertising

  2. Try the ItemDataBound event for the grid...

    private void dgGrid1_ItemDataBound(Object sender, DataGridItemEventArgs e)
    {

    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem )
    {
    LinkButton lbtnDelete = e.Item.FindControl("lbtnDelete") as LinkButton;
    lbtnDelete.Attributes.Add("onclick", "return confirm('Delete this record?')");
    }
    }

    "Arne" wrote:

    > I have a delete column in a datagird.
    > I would like to execute
    > cmdDelete.Attributes.Add("onclick", "return confirm('Delete this record?');")
    > somewhere.
    > Where is the right place to put this code?
     
    =?Utf-8?B?RGF2ZQ==?=, Apr 28, 2005
    #2
    1. Advertising

  3. That doesn't work for a linkbutton with an autopostback.

    "Dave" wrote:

    > Try the ItemDataBound event for the grid...
    >
    > private void dgGrid1_ItemDataBound(Object sender, DataGridItemEventArgs e)
    > {
    >
    > if (e.Item.ItemType == ListItemType.Item ||
    > e.Item.ItemType == ListItemType.AlternatingItem )
    > {
    > LinkButton lbtnDelete = e.Item.FindControl("lbtnDelete") as LinkButton;
    > lbtnDelete.Attributes.Add("onclick", "return confirm('Delete this record?')");
    > }
    > }
    >
    > "Arne" wrote:
    >
    > > I have a delete column in a datagird.
    > > I would like to execute
    > > cmdDelete.Attributes.Add("onclick", "return confirm('Delete this record?');")
    > > somewhere.
    > > Where is the right place to put this code?
     
    =?Utf-8?B?QXJuZQ==?=, Apr 28, 2005
    #3
  4. Steve C. Orr [MVP, MCSD], Apr 29, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Calvin Lai
    Replies:
    4
    Views:
    7,950
    Calvin Lai
    Feb 4, 2004
  2. Dexter
    Replies:
    2
    Views:
    507
    Dexter
    Oct 3, 2004
  3. Saravana
    Replies:
    1
    Views:
    525
    =?Utf-8?B?UHN5Y2hv?=
    Oct 4, 2004
  4. =?iso-8859-1?B?UultaQ==?=
    Replies:
    7
    Views:
    2,500
    S. Justin Gengo
    Oct 26, 2005
  5. Amelyan

    Confirm Delete in DataGrid

    Amelyan, Apr 29, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    353
    Steve C. Orr [MVP, MCSD]
    Apr 30, 2005
Loading...

Share This Page