Example E131
Visible to All Users

Grid View for ASP.NET Web Forms - How to include a row key value into the delete confirmation dialog

This example demonstrates how to include a row key value in the delete confirmation dialog.

Implementation Details

In this example, DataItemTemplate contains a link element.

ASPx
<dxwgv:GridViewDataTextColumn Name="Delete" > <DataItemTemplate> <a id="DeleteButton" href="javascript:OnLinkClick(<%# Container.KeyValue.ToString()%>, <%# Container.VisibleIndex.ToString()%>);">Delete</a> </DataItemTemplate> </dxwgv:GridViewDataTextColumn>

When a user clicks the link, the OnLinkClick function displays a confirmation dialog with the row key value.

JavaScript
function OnLinkClick(id, visibleIndex) { if (confirm('Do you wish to delete row with ID = ' + id + '?')) ASPxGridView1.DeleteRow(visibleIndex); }

Files to Review

More Examples

Example Code

WebSite/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Customize_Confirm_Delete" %> <%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.14.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dxe" %> <%@ Register Assembly="DevExpress.Web.v13.1, Version=13.1.14.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dxwgv" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>How to include a deleted row KeyField value into the delete confirmation dialog </title> <script type="text/javascript"> function OnLinkClick(id, visibleIndex) { if (confirm('Do you wish to delete row with ID = ' + id + '?')) ASPxGridView1.DeleteRow(visibleIndex); } </script> </head> <body> <form id="form1" runat="server"> <div> <dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" ClientInstanceName="ASPxGridView1" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" KeyFieldName="job_id" Width="845px" OnRowDeleting="ASPxGridView1_RowDeleting"> <Columns> <dxwgv:GridViewDataTextColumn FieldName="job_id" ReadOnly="True" /> <dxwgv:GridViewDataTextColumn FieldName="job_desc" /> <dxwgv:GridViewDataTextColumn FieldName="min_lvl" /> <dxwgv:GridViewDataTextColumn FieldName="max_lvl" /> <dxwgv:GridViewDataTextColumn Name="Delete" > <DataItemTemplate> <a id="DeleteButton" href="javascript:OnLinkClick(<%# Container.KeyValue.ToString()%>, <%# Container.VisibleIndex.ToString()%>);"> Delete</a> </DataItemTemplate> </dxwgv:GridViewDataTextColumn> </Columns> </dxwgv:ASPxGridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/pubs.mdb" SelectCommand="SELECT * FROM [jobs]" DeleteCommand="DELETE FROM [jobs] WHERE [job_id] = ?" InsertCommand="INSERT INTO [jobs] ([job_id], [job_desc], [min_lvl], [max_lvl]) VALUES (?, ?, ?, ?)" UpdateCommand="UPDATE [jobs] SET [job_desc] = ?, [min_lvl] = ?, [max_lvl] = ? WHERE [job_id] = ?"> <DeleteParameters> <asp:Parameter Name="job_id" Type="Int16" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="job_desc" Type="String" /> <asp:Parameter Name="min_lvl" Type="Byte" /> <asp:Parameter Name="max_lvl" Type="Byte" /> <asp:Parameter Name="job_id" Type="Int16" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="job_id" Type="Int16" /> <asp:Parameter Name="job_desc" Type="String" /> <asp:Parameter Name="min_lvl" Type="Byte" /> <asp:Parameter Name="max_lvl" Type="Byte" /> </InsertParameters> </asp:AccessDataSource> </div> </form> </body> </html>

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.