Click here to Skip to main content
16,020,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i had a datagrid view with multicoloumn i need to delete grid recods with confirmation, in code behind file the event lnkDelete_Click not firing can any help me to delete the recodrs in grid

ASP.NET
<Columns>

             <asp:CommandField Visible="false" />
             <asp:BoundField DataField="EntryTypeName" Visible="true" HeaderText="EntryTypeName"></asp:BoundField>
             <asp:BoundField DataField="ProductName" Visible="true" HeaderText="ProductName"></asp:BoundField>
             <asp:BoundField DataField="VersionNumber" Visible="true" HeaderText="Version "></asp:BoundField>
             <asp:BoundField DataField="BugID" Visible="true" HeaderText="BugID"></asp:BoundField>
             <asp:BoundField DataField="SupportID" Visible="true" HeaderText="SupportID"></asp:BoundField>
             <asp:BoundField DataField="Description" Visible="true" HeaderText="Description"></asp:BoundField>
             <asp:BoundField DataField="Date" Visible="true" HeaderText="Date"></asp:BoundField>
             <asp:BoundField DataField="Effort" Visible="true" HeaderText="Effort"></asp:BoundField>

              <asp:TemplateField>
              <ItemTemplate>
                  <asp:LinkButton ID="lnkDelete" Runat="server" onclick="lnkDelete_Click" OnClientClick="return confirm('Are you sure you?');"
                      CommandName="Delete">Delete</asp:LinkButton>
              </ItemTemplate>
              </asp:TemplateField>

          </Columns>
Posted
Updated 10-Jul-13 1:10am
v3

please assign OnRowCommand

1.OnRowCommand="gvProductReceive_RowCommand"
XML
<asp:GridView ID="gvProductReceive" Width="100%" runat="server" AllowPaging="True"
    AutoGenerateColumns="False" CellPadding="4" GridLines="None" AllowSorting="True"
    ForeColor="#333333" PageSize="30" OnPageIndexChanging="gvProductReceive_PageIndexChanging"
    OnRowCommand="gvProductReceive_RowCommand" OnRowDataBound="gvProductReceive_RowDataBound">
    <RowStyle BackColor="#E3EAEB" />


2.
XML
<asp:ImageButton ID="ImgDelete" runat="server" CausesValidation="False" CommandName="CmdDelete"
        CommandArgument='<%# bind("ReceivedId") %>' ImageUrl="~/Images/delete.png" Text=""
        AlternateText="Delete" ToolTip="Delete" />
</ItemTemplate>


3. Catch the event on .cs file
C#
protected void gvProductReceive_RowCommand(object sender, GridViewCommandEventArgs e)
{

    int _ownerDetailId;
    arrayDelete = new ArrayList();
    if (e.CommandName == "CmdDelete")
    {
        _ownerDetailId = Convert.ToInt32(e.CommandArgument.ToString());

    }
}

hopefully it works
Best regards
 
Share this answer
 
v3
Comments
kesav prakash 10-Jul-13 9:34am    
how to to get the datagridview selected cell value(text) without using the row.cell[index]
Riasat Azim Dip 10-Jul-13 9:46am    
I think your Question is
DataGrid view delete button firing event problem in ASP.net :)
you have to do this by row.cell[index] another techniques is not available to me.
Do some RND :)
 
Share this answer
 
you can use RowCommand_event of Gridview and in that event delete the record as per your requirement

try this
rowcommand event of gridview[^]
 
Share this answer
 
Comments
kesav prakash 10-Jul-13 9:35am    
how to to get the datagridview selected cell value(text) without using the row.cell[index]
Naz_Firdouse 10-Jul-13 9:40am    
RowBound event is for a row...so without specifying index,which cell value you want to retrieve?
Remove
CommandName="Delete"
and try!
 
Share this answer
 
Comments
kesav prakash 10-Jul-13 7:22am    
i already done ya, may i know in which event i need to write the delete code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900