我希望删除GridView中的一行。因此,我需要ID,如何在GridView_RowDeleting事件中获取该行的ID?
以下是GridView的列列表,
<Columns>
<asp:TemplateField HeaderText="S.No." ControlStyle-Width="100%" ItemStyle-Width="30px">
<ItemTemplate>
<asp:Label ID="lblSrno" runat="server" Text=''
<%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="100%" />
<ItemStyle Width="30px" />
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label runat="server" ID="lblDrawingID" Text=''
<%# Bind("DrawingID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CustDrawingNbr" HeaderText="Customer Drawing No." />
<asp:TemplateField HeaderText="Status" ControlStyle-Width="100px" ItemStyle-Width="100px">
<ItemTemplate>
<asp:DropDownList ID="ddlStatus" runat="server" Width="100px" Enabled="false">
</asp:DropDownList>
</ItemTemplate>
<ControlStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label runat="server" ID="lblDrawingPGMAStatusID" Text=''
<%# Bind("StatusID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label runat="server" ID="lblDrawingPGMAID" Text=''
<%# Bind("PGMAID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="true" HeaderText="Action" ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:CommandField>
</Columns>
这里我使用GridView填充了一个DataTable。DataTable的列是DrawingID、CustDrawingNbr、JobOrderID、StatusID、PGMAID和SeqNo。因此,我想在单击删除按钮时获取DrawingID。
到目前为止, 我尝试了以下几件事情。但是没有任何一件事情能够得到所需的结果。
但是上述所有方法都未能得到所需的结果。
- Label lblDraw = (Label)gvApplicablePGMASearch.Rows[e.RowIndex].Cells[2].FindControl("lblDrawingID"); int drawid = Convert.ToInt32(lblDraw.Text);
- string drawid = gvApplicablePGMASearch.DataKeys[e.RowIndex].Value.ToString();
- string id = gvApplicablePGMASearch.SelectedDataKey.Value.ToString();