繁体   English   中英

使用取消图像从GridView中删除行

[英]Delete Row From GridView using cancel Image

你好朋友我有一个要求,我想从图像按钮删除我的gridview中删除一行。 我写这样的代码

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" Width="200" GridLines="None" OnRowCancelingEdit="GridView2_RowCancelingEdit" OnRowDeleting="GridView2_RowDeleting" >
                                                <Columns>
                                                    <asp:TemplateField HeaderText="Sl.No">
                                                        <ItemTemplate>
                                                            <%# Container.DataItemIndex + 1 %>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Supportiong Documents">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblSupportingDocument" runat="server" Text='<%#Eval("SupportingDocument") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Delete" ShowHeader="false">
                                                        <ItemTemplate>
                                                            <asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/images/delete.png" CommandName="Cancel" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>

                                                </Columns>
                                            </asp:GridView>

而我的代码背后是

 protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
        {
           if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
            {
                bind_SupportingDocumentGrid(id);

            }

        }
    }

void bind_SupportingDocumentGrid(int id)
    {
        List<TblFinancialTransactionSupportDocumentDetail> lstFTSD = ServiceAccess.GetProxy().GetAllFinancialTransactionSupportDocumentDetails();
        var x = (from y in lstFTSD
                 where y.FinancialTransactionId == id
                 select new
                 {
                     y.SupportingDocument
                 }).ToList();
        GridView2.DataSource = x;
        GridView2.DataBind();
    }
protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        List<TblFinancialTransactionSupportDocumentDetail> lstFTSD = ServiceAccess.GetProxy().GetAllFinancialTransactionSupportDocumentDetails();
        Label lblSupportingDocument = (Label)GridView2.Rows[e.RowIndex].FindControl("lblSupportingDocument");
        var x = (from y in lstFTSD
                 where y.FinancialTransactionId == Convert.ToInt32(Request.QueryString["id"]) &&
                 y.SupportingDocument == (lblSupportingDocument).ToString()
                 select new
                 {
                     y.FinancialTransactionSupportDocumentDetailId
                 }).ToList();
        ServiceAccess.GetProxy().DeleteFinancialTransactionSupportDocumentDetail(Convert.ToInt32(x));
        bind_SupportingDocumentGrid(Convert.ToInt32(Request.QueryString["id"]));
    }

但不知何故它现在正在工作,我发现使用断点是“GridView2_RowDeleting”事件不生成。 亲切的帮助我克服这个问题。 提前致谢。

您应该有一个CommandName为“Delete”的按钮:

<asp:TemplateField HeaderText="Delete" ShowHeader="false">
   <ItemTemplate>
      <asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/images/delete.png" **CommandName="Delete"** />
   </ItemTemplate>
</asp:TemplateField>

尝试与事件一起提供句柄

protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) Handles YourDeletebutton.click

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM