Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Add a confirm box to a LinkButton in datagrid

Reply
Thread Tools

Add a confirm box to a LinkButton in datagrid

 
 
Danny Ni
Guest
Posts: n/a
 
      01-29-2005
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


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      01-29-2005
"Danny Ni" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding javascript window.confirm to linkbutton darrel ASP .Net 19 10-22-2010 02:15 PM
OnClientClick in an asp:LinkButton - using confirm() doesn't work inevery browser dddan ASP .Net 2 12-14-2007 08:16 PM
Linkbutton does not look like a linkbutton Sathyaish ASP .Net 3 09-08-2005 09:41 AM
Confirm Delete popup from a LinkButton in a repeater Sandy ASP .Net 1 06-11-2004 05:37 PM
confirm box when clicking Delete Linkbutton in DG Calvin Lai ASP .Net 4 02-04-2004 03:03 PM



Advertisments