Add a confirm box to a LinkButton in datagrid

Discussion in 'ASP .Net' started by Danny Ni, Jan 29, 2005.

  1. Danny Ni

    Danny Ni Guest

    Hi,

    I have a LinkButton inside a datagrid, when this LinkButton is clicked, the
    program deleete a record in database. I would like to add a confirmation on
    client side. I know I can do Attributes.Add("onclick",...) to Buttons not in
    datagrid. But how do I do it for LinkButton in datagrid?

    TIA
     
    Danny Ni, Jan 29, 2005
    #1
    1. Advertising

  2. Danny Ni

    Mark Rae Guest

    "Danny Ni" <> wrote in message
    news:...

    > I have a LinkButton inside a datagrid, when this LinkButton is clicked,
    > the
    > program deleete a record in database. I would like to add a confirmation
    > on
    > client side. I know I can do Attributes.Add("onclick",...) to Buttons not
    > in
    > datagrid. But how do I do it for LinkButton in datagrid?


    public void dgrd_ItemCreated(Object sender, DataGridItemEventArgs e)
    {
    LinkButton cmdDelete;
    if((e.Item.ItemType == ListItemType.Item)
    || (e.Item.ItemType == ListItemType.AlternatingItem)
    || (e.Item.ItemType == ListItemType.EditItem))
    {
    cmdDelete = (LinkButton)e.Item.Cells[0].Controls[0];
    cmdDelete.Attributes.Add("onclick", "return confirm('Are you sure you
    want to delete this record?');");
    }
    }

    The above example assumes that your LinkButton is the first Control in the
    first column of the datagrid - change the e.Item.Cells[0].Controls[0] values
    accordingly if it is not.
     
    Mark Rae, Jan 29, 2005
    #2
    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,954
    Calvin Lai
    Feb 4, 2004
  2. Sandy
    Replies:
    1
    Views:
    7,243
    =?Utf-8?B?TWF1cmljaW9ERw==?=
    Jun 11, 2004
  3. Sathyaish
    Replies:
    3
    Views:
    3,118
    Sathyaish
    Sep 8, 2005
  4. darrel
    Replies:
    19
    Views:
    1,147
    Vijay Kumar
    Oct 22, 2010
  5. dddan
    Replies:
    2
    Views:
    1,034
    David C
    Dec 14, 2007
Loading...

Share This Page