如何通过单击删除按钮删除vb.net中gridview中的选定行

时间:2015-01-27 10:12:31

标签: vb.net gridview

下面的代码是删除第一行而不是选中的行。

Protected Sub LinkBtn_Del_Click(sender As Object, e As EventArgs)
        Dim intpartID As Integer = gvParticipant.DataKeys(0).Value
        Dim comPart As New SqlCommand("usp_Participant_Delete", consql)
        comPart.CommandType = CommandType.StoredProcedure
        comPart.Parameters.Add("@ParID", SqlDbType.Int).Value = intpartID
        consql.Open()
        comPart.ExecuteNonQuery()
        consql.Close()
        selectParticipant()
        MultiViewall.SetActiveView(viewDisplayWorkshop)
    End Sub

1 个答案:

答案 0 :(得分:0)

在调用DataKeys()方法时,您应该获得GridView的选定索引,而不是传递0。在您的情况下,只需使用gvParticipant.SelectedIndex

GridView.SelectedIndex Property

相关问题