Groups | Blog | Home
all groups > asp.net datagrid control > november 2006 >

asp.net datagrid control : Alert to confirm deletes in the new GridView control



dev648237923
11/17/2006 10:39:13 AM
I want to have an alert to confirm deletes in the GridView. I have seen
posting for doing it in DataGrid but I can not get it to work in the new
GridView. I tried in GridView1_RowCommand I tried something like:

((LinkButton)GridView1.SelectedRow.FindControl("lbDelete")).Attributes.Add(
"onClick", "return confirm('Are you sure you want to delete this row?');");

Any ideas would be appretiated!

Thank you!




dev648237923
11/17/2006 10:42:50 AM
I just found an article that looks like it will work well for me...
http://www.codeproject.com/aspnet/GridViewConfirmDelete.asp
Thank you!

[quoted text, click to view]

stcheng NO[at]SPAM online.microsoft.com
11/20/2006 12:00:00 AM
Hi dev648237923,

If you're using TemplateField, it is convenient for us to customize the
controls in the template. The code project article you mentioend use
"RowDataBound" event to add the "confirm delete" javascript for the
delete button. You can also do it through the "RowCreated" event.

In addition, in ASP.NET 2.0, button or LinkButton control provide the
"OnClientClick" property that can let you add client-side click script.
Therefore, you can also add the "confirm deleting" script in the LinkButton
or Button's "OnClientClick" property. e.g


=========================
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField ShowHeader="False">
..............
<ItemTemplate>
.............................
<asp:LinkButton ID="LinkButton2" runat="server"

OnClientClick="if(confirm('Are you sure to
delete this item?') == false){return false;}"

CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
==============================

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button