I want to delete one specific row in a gridview. So I need an ID, How can I get the row id in the GridView_RowDeleting event?
Here is a list of GridView columns,
<Columns>
<asp:TemplateField HeaderText="S.No." ControlStyle-Width="100%" ItemStyle-Width="30px">
<ItemTemplate>
<asp:Label ID="lblSrno" runat="server" Text=''
<%
</ItemTemplate>
<ControlStyle Width="100%" />
<ItemStyle Width="30px" />
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label runat="server" ID="lblDrawingID" Text=''
<%
</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=''
<%
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label runat="server" ID="lblDrawingPGMAID" Text=''
<%
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="true" HeaderText="Action" ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:CommandField>
</Columns>
Here I populate one data file using a GridView. The columns of the DataTable are DrawingID, CustDrawingNbr, JobOrderID, StatusID, PGMAID, SeqNo. So I want to get a DrawingID when I click the Delete button.
So far, I have tried the following. But nothing gave the desired result.
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();
.