confirm box when clicking Delete Linkbutton in DG

C

Calvin Lai

Hi all,

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

Guest

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
 
M

Marshal Antony

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
 
M

Marshal Antony

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,
 
C

Calvin Lai

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,
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top