"Danny Ni" <dn*@yahoo.co m> wrote in message
news:eT******** ******@TK2MSFTN GP09.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_ItemCreate d(Object sender, DataGridItemEve ntArgs e)
{
LinkButton cmdDelete;
if((e.Item.Item Type == ListItemType.It em)
|| (e.Item.ItemTyp e == ListItemType.Al ternatingItem)
|| (e.Item.ItemTyp e == ListItemType.Ed itItem))
{
cmdDelete = (LinkButton)e.I tem.Cells[0].Controls[0];
cmdDelete.Attri butes.Add("oncl ick", "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.