hello friend i have a requirement in which i want to delete a row from my gridview on image button delete. i write the code like this
<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>
and my code behind is
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"]));
}
but somehow it is now working and i found using breakpoint is "GridView2_RowDeleting" event is not generating. kind help me to overcome from this problem. thanks in advance.
You should have a button whose CommandName is "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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.