[英]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.