Alert to confirm deletes in the new GridView control

D

dev648237923

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!
 
S

Steven Cheng[MSFT]

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.
 

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,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top