confirm box when clicking Delete Linkbutton in DG

  • Thread starter Thread starter Calvin Lai
  • Start date Start date
C

Calvin Lai

Hi all,

Does anyone know how I could add a confirm (client side) feature on those
Delete Linkbutton in DataGrid? Thanks,
 
Hi Calvin,

Try adding something like the following to the Page Load event or your own event after the data grid loads:

Linkbutton.Attributes.Add("onclick", "return confirm('Are you Sure you want to delete this?');")

HTH,
Jeremy
 
Hi Calvin,
If you want to show up a javascript confirm before you delete every
record in the datagrid :

Put the javascript function given below in your aspx page
<script language='JavaScript'>
function ConfirmDelete()
{
if(confirm("Do you want to delete this record?")==true)
return true;
else
return false;
}

</script>
In your code behind :
Under the ItemDataBound event of your datagrid use this code :
If BtnDel is the ID of your LinkButton in the datagrid,

LinkButton lb;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

lb = (LinkButton)e.Item.Cells[0].FindControl("BtnDel");
// 0 index is used for cell assuming BtnDel is the first item in the
datagrid.
lb.Attributes.Add("onclick", "return ConfirmDelete();")
}

Hope this helps,
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com
 
Calvin,
The code I sent is to use before deleting each record(not every)..to
avoid confusion..
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com

Marshal Antony said:
Hi Calvin,
If you want to show up a javascript confirm before you delete every
record in the datagrid :

Put the javascript function given below in your aspx page
<script language='JavaScript'>
function ConfirmDelete()
{
if(confirm("Do you want to delete this record?")==true)
return true;
else
return false;
}

</script>
In your code behind :
Under the ItemDataBound event of your datagrid use this code :
If BtnDel is the ID of your LinkButton in the datagrid,

LinkButton lb;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

lb = (LinkButton)e.Item.Cells[0].FindControl("BtnDel");
// 0 index is used for cell assuming BtnDel is the first item in the
datagrid.
lb.Attributes.Add("onclick", "return ConfirmDelete();")
}

Hope this helps,
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com

Calvin Lai said:
Hi all,

Does anyone know how I could add a confirm (client side) feature on those
Delete Linkbutton in DataGrid? Thanks,
 
Thanks all your input.


Marshal Antony said:
Calvin,
The code I sent is to use before deleting each record(not every)..to
avoid confusion..
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com

Marshal Antony said:
Hi Calvin,
If you want to show up a javascript confirm before you delete every
record in the datagrid :

Put the javascript function given below in your aspx page
<script language='JavaScript'>
function ConfirmDelete()
{
if(confirm("Do you want to delete this record?")==true)
return true;
else
return false;
}

</script>
In your code behind :
Under the ItemDataBound event of your datagrid use this code :
If BtnDel is the ID of your LinkButton in the datagrid,

LinkButton lb;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

lb = (LinkButton)e.Item.Cells[0].FindControl("BtnDel");
// 0 index is used for cell assuming BtnDel is the first item in the
datagrid.
lb.Attributes.Add("onclick", "return ConfirmDelete();")
}

Hope this helps,
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com

Calvin Lai said:
Hi all,

Does anyone know how I could add a confirm (client side) feature on those
Delete Linkbutton in DataGrid? Thanks,
 
Back
Top