Add a confirm box to a LinkButton in datagrid

D

Danny Ni

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
 
M

Mark Rae

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top