如何为此网格添加删除确认? [英] how to add delete confirmation for this grid?

查看:81
本文介绍了如何为此网格添加删除确认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以说出如何为此网格添加删除构造吗?
我有一个事件OnRowDeleting="grdContacts_RowDeleting",我无法为此添加删除确认.请在此帮助我!

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

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

推荐答案

在Codeproject上查看此主题:使用确认删除GridView [ ^ ]
See this topic on Codeproject: GridView Delete, with Confirmation[^]




请在GridView1_RowDataBound事件上尝试类似的操作.
Hi,

Please try something like this on GridView1_RowDataBound event.
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.


这篇关于如何为此网格添加删除确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆