<asp:CommandField HeaderText="Delete" ShowDeleteButton="true" ShowHeader="true" />
Protected Sub GridView1_RowDeleting1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim cmd As New SqlCommand("delete from user where [ID]=@ID", con)
Dim title As String = "Confirm ??"
Dim msg As String = "Are you sure you want to delete this record?"
Dim style As MsgBoxStyle = MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation
Dim response As MsgBoxResult
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
'Dim eIndex As Integer = GridView1.SelectedIndex
Dim eIndex As Integer = e.RowIndex
log.writeLog(MapPath(logName), eIndex)
GridView1.DeleteRow(eIndex)
End If
End Sub
จะลบแถวจาก gridview ค่ะ แต่พอกดyes ที่ msg box ไปแล้ว มันขึ้นให้กดใหม่อีกเรื่อยๆ
จะลบ แถวได้ด้วยวิธีไหนอ่ะคะ
ขอเป็นตัวอย่างโค้ดนะคะ ขอบคุณคะ
delete row จาก gridview vb.net
Protected Sub GridView1_RowDeleting1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim cmd As New SqlCommand("delete from user where [ID]=@ID", con)
Dim title As String = "Confirm ??"
Dim msg As String = "Are you sure you want to delete this record?"
Dim style As MsgBoxStyle = MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation
Dim response As MsgBoxResult
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
'Dim eIndex As Integer = GridView1.SelectedIndex
Dim eIndex As Integer = e.RowIndex
log.writeLog(MapPath(logName), eIndex)
GridView1.DeleteRow(eIndex)
End If
End Sub
จะลบแถวจาก gridview ค่ะ แต่พอกดyes ที่ msg box ไปแล้ว มันขึ้นให้กดใหม่อีกเรื่อยๆ
จะลบ แถวได้ด้วยวิธีไหนอ่ะคะ
ขอเป็นตัวอย่างโค้ดนะคะ ขอบคุณคะ