Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone please say how to add delete conformation for this grid?
I have an event OnRowDeleting="grdContacts_RowDeleting" I am unable to add delete confirmation to this Please help me out in this!!!!

XML
<asp:GridView   ID="grdContacts" runat="server" ShowFooter="false" AutoGenerateColumns="false" SkinID="View" OnRowEditing="grdContacts_RowEditing" OnRowDeleting="grdContacts_RowDeleting">
                                                       <Columns>
                                                           <asp:TemplateField HeaderText="Contact Type"><ItemTemplate><asp:Label ID="lblContactsContactType" runat="server" Text="<%# ((EDDY.IMS20.Entity.Interface.IContactType)(((EDDY.IMS20.Entity.Interface.IContact)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheContact)).TheContactType)).ContactTypeName%>"></asp:Label></ItemTemplate></asp:TemplateField>
                                                           <asp:TemplateField HeaderText="Name"><ItemTemplate><asp:Label ID="lblContactsName" runat="server" Text="<%# ((EDDY.IMS20.Entity.Interface.IContact)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheContact)).FirstName + ' ' + ((EDDY.IMS20.Entity.Interface.IContact)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheContact)).LastName%>"></asp:Label></ItemTemplate></asp:TemplateField>
                                                           <asp:TemplateField HeaderText="Phone"><ItemTemplate><asp:Label ID="lblContactsPhone" runat="server" Text="<%# ((EDDY.IMS20.Entity.Interface.IContact)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheContact)).Phone%>"></asp:Label></ItemTemplate></asp:TemplateField>
                                                           <asp:TemplateField HeaderText="Email Address"><ItemTemplate><asp:HyperLink ID="lblContactsEmail" runat="server" Text="<%# ((EDDY.IMS20.Entity.Interface.IContact)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheContact)).Email%>" NavigateUrl="#"></asp:HyperLink></ItemTemplate></asp:TemplateField>
                                                           <asp:TemplateField HeaderText="Address"><ItemTemplate><asp:Label ID="lblAddress1" runat="server" Text="<%# ((EDDY.IMS20.Entity.Interface.IAddress)(((EDDY.IMS20.Entity.Interface.IContact)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheContact)).TheAddress)).Address1%>"></asp:Label></ItemTemplate></asp:TemplateField>
                                                           <asp:TemplateField Visible="true">
                                                               <ItemTemplate>
                                                                   <asp:HiddenField ID="hdnContactsEntityMarkedFor" runat="server" Value='<%# ((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).entityMarkedFor%>' />
                                                                   <asp:HiddenField ID="hdnContactsContactClientD" runat="server" Value='<%# ((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).ClientContactId%>' />
                                                                   <asp:HiddenField ID="hdnContactsContactIsEnabled" runat="server" Value='<%# ((EDDY.IMS20.Entity.Interface.ICommonDatabaseEntities)(((EDDY.IMS20.Entity.Interface.IClientContact)(Container.DataItem)).TheCommonDatabaseEntities)).IsEnabled%>' />
                                                               </ItemTemplate>
                                                           </asp:TemplateField>
                                                           <asp:CommandField       HeaderText="Action"
                                                                                   ShowDeleteButton='true'
                                                                                   ShowEditButton='true'
                                                                                   ShowCancelButton="false"
                                                                                   ButtonType="Image"
                                                                                   EditImageUrl="~/Images/Icons/edit.png"
                                                                                   DeleteImageUrl="~/Images/Icons/remove.png"
                                                                                   ItemStyle-HorizontalAlign="Center"
                                                                                   HeaderStyle-HorizontalAlign="Center" >
                                                           </asp:CommandField>
                                                       </Columns>
                                                   </asp:GridView>
Posted
Updated 15-Apr-11 4:29am
v2

See this topic on Codeproject: GridView Delete, with Confirmation[^]
 
Share this answer
 
Comments
Tarun.K.S 15-Apr-11 10:21am    
Comment from Gautham:

but I am not using any link button in my code!! all I am using it event " grdContacts_RowDeleting" so is there any way to do it in the event?
Hi,

Please try something like this on GridView1_RowDataBound event.
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //In this sample, there are  3 buttons and the second one is Delete button, that's why we use the index 2
        //indexing goes as 0 is button #1, 1 Literal (Space between buttons), 2 button #2, 3 Literal (Space) etc.
        ((Button)e.Row.Cells[0].Controls[2]).OnClientClick = "return confirm('"Do you really want to delete?');";
    }
}

Good Luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900