Tuesday, July 23, 2013

link button in gridview to delete a record in asp.net

To delete a record when the user clicks on a link button of a grid view in asp.net, use the following code block

VB.Net Code

<asp:TemplateField HeaderText="Delete">
                                <ItemTemplate>
                                    <span onclick="return confirm('Are you sure to Delete the user?')">
                                        <asp:LinkButton runat="server" ID="lnkDel" Text="Delete" CommandArgument='<%# Eval("Id") %>'
                                            CommandName="Delete" CausesValidation="False"></asp:LinkButton>
                                </ItemTemplate>
                                <HeaderStyle Width="60px"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Center"></ItemStyle>
                            </asp:TemplateField>

    Protected Sub gv_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvUsers.RowDeleting
        Dim _Result As String
        _Result = gv.Rows(e.RowIndex).Cells(0).Text)
    End Sub

No comments:

Post a Comment