be the datagrid that will contain a list of linkbutton (lkDelete2) in our case used to delete a specific row of data in your table.
Add the following column in your Datagrid.
<asp:datagrid id="m_dg1" style="Z-INDEX: 111; LEFT: 208px; POSITION: absolute; TOP: 224px"
<asp:TemplateColumn HeaderText="Delete Referral 1">
<asp:LinkButton ID="lkDelete2" Runat="server" CommandName="Delete2" OnClient="return confirm('Are you sure you want to delete ?');">
You can then go on to add an ItemCreated Event handler for that datagrid. For the sake of our exercise we will call this hander OnItemCreate
If you don't know how to add an event handler for your datagrid Do the following:
your DataGrid in Design mode ( Not HTML)
- In the Property
window click on the event Button
( the Lightening buttonn Yellow on top ).
- Type the name
of the function that you want to handle any specific event ( in our case the event is ItemCreated
and the function name is OnItemCreate
- Hit Enter
We are almost done.
Now in the code behind fill in
the OnItemCreate function with the following code
private void OnItemCreate(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
Control clb = (Control)e.Item.FindControl("lkDelete2");
if(clb!=null && clb.GetType() != typeof(LinkButton))
LinkButton lb = (LinkButton)clb;
if(lb != null)
lb.Attributes.Add("onClick", "return confirm('Are you sure you want to delete ?');");
Not that magic actually. What is annoying is Y wont VS let me directly add it in the ASP code.
But then again who am I to discuss Microsoft ways. This issue if fixed in asp.net 2.0.