0
你好朋友我有一個要求,我想從我的gridview刪除一行圖像按鈕刪除。 我寫這樣的從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」事件不產生。 類可以幫助我克服這個問題。 在此先感謝。
感謝現在,它正在沿着給手柄 – akvickyit7