Hi guys,
I have a datagrid with the delete command in the template. What I want is, whenever I click delete, I should be able to delete that particular row. My code is like below.
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim strConn As String = "Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;"
Dim DeleteCmd As String = "DELETE from COntact_List Where id = @System_ID"
Dim MyConn As New SqlConnection(strConn)
Dim Cmd As New SqlCommand(DeleteCmd, MyConn)
Cmd.Parameters.Add(New SqlParameter("@System_ID", DataGrid1.DataKeys(CInt(e.Item.ItemIndex))))
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
BindData()
End Sub
Thanks in advanced,
Edora Theo
I have a datagrid with the delete command in the template. What I want is, whenever I click delete, I should be able to delete that particular row. My code is like below.
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim strConn As String = "Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;"
Dim DeleteCmd As String = "DELETE from COntact_List Where id = @System_ID"
Dim MyConn As New SqlConnection(strConn)
Dim Cmd As New SqlCommand(DeleteCmd, MyConn)
Cmd.Parameters.Add(New SqlParameter("@System_ID", DataGrid1.DataKeys(CInt(e.Item.ItemIndex))))
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
BindData()
End Sub
Thanks in advanced,
Edora Theo