"Danny Ni" <dn*@yahoo.com> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
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.