hi friends,i have a problem in my gridview control,actually i am having a gridview and bind the gridview with the database,in that gridview i provide a link button called delete,when i click the delete button its shows an error,after reloading the page the current record is deleted,but whenever the delete button is pressed its shows the following error
The GridView 'GridView1' fired event RowDeleting which wasn't handled.
but whenever i reload the project the record will be deleted,here is my code
<asp:GridView runat="server" AutoGenerateColumns="false"
ID="GridView1">
<Columns>
<asp:BoundField DataField="empname" HeaderText="EMPLOYEE NAME"
SortExpression="empname" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkDelete"
Text="Delete" CommandName="delete"
CommandArgument='<%# DataBinder.Eval(Container.dataitem, "empid")%>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
connection.ConnectionString = ("Data Source=RIFAYEE-PC;Initial Catalog=HumanResource;Integrated Security=True")
cmd = New SqlCommand("select empid,empname from emp ORDER BY empid", connection)
da = New SqlDataAdapter(cmd)
dt.Clear()
connection.Open()
da.Fill(dt)
If dt.Rows.Count > 0 Then
GridView1.DataSource = dt
GridView1.DataBind()
Else
Response.Write("no data found")
End If
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView1.RowCommand
If (e.CommandName = "delete") Then
Dim empid = e.CommandArgument.ToString
deleteempid(empid)
End If
End Sub
Private Sub deleteempid(ByVal empid As String)
cmd = New SqlCommand("delete from emp where empid=@empid", connection)
Dim empidparameter = New SqlParameter("@empid", empid)
empidparameter.Value = empid
cmd.Parameters.Add(empidparameter)
cmd.ExecuteNonQuery()
Response.Write("deleted successfully")
End Sub