我在gridview中使用此代码进行行删除。它应该是这样的“当它删除一行时,取第5行,序列号为5,行号6的串行字段应该变为5.意味着在删除一行后减少序列号。”但是当我用序列号5删除第5行时,它没有发生,第6行保持不变。
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
For Each control As Control In e.Row.Cells(0).Controls
Dim DeleteButton As LinkButton = TryCast(control, LinkButton)
If DeleteButton IsNot Nothing AndAlso DeleteButton.Text = "Delete" Then
DeleteButton.OnClientClick = "return(confirm('Are you sure you want to delete this record?'))"
End If
Next
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Delete" Then
' get the categoryID of the clicked row
Dim Serial As Integer = Convert.ToInt32(e.CommandArgument)
' Delete the record
Dim mycommand As New SqlCommand("DELETE FROM target WHERE SlNo = '" & Serial & "'", con)
con.Open()
mycommand.ExecuteNonQuery()
con.Close()
bindphoto2()
Label1.Text = "File has been deleted succefully"
End If
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim Serial As Integer = CInt(GridView1.DataKeys(e.RowIndex).Value)
Dim mycommand As New SqlCommand("DELETE FROM target WHERE SlNo = '" & Serial & "'", con)
con.Open()
mycommand.ExecuteNonQuery()
con.Close()