Need to delete row in gridview but must not affect that row in the database.
-
Hi there! I am having difficulty in deleting a row from a gridview. I would like to delete a row of data in a gridview using checkbox but at the same time would not delete that data from the database. I have tried using deleteRow method but am still struggling. Is there a work-around solution for this? BtnDelete Method Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click If Not IsPostBack Then Dim Row2 As GridViewRow Dim rowCell As String = "" Dim count As Integer = 0 Dim test As Integer = 0 Try For Each row As GridViewRow In GridView1.Rows Dim checkBxText As String = CType(row.FindControl("chkDelete"), CheckBox).Text Row2 = GridView1.Rows(count) rowCell = Row2.Cells(2).Text Dim cb As CheckBox = DirectCast(row.FindControl("chkDelete"), CheckBox) If cb.Checked Then Try 'GridView1.Row(row.RowIndex).Delete() MsgBox(row.RowIndex) GridView1.DeleteRow(row.RowIndex) Catch ex As Exception 'MsgBox(count) GridView1.DataBind() End Try Else End If count += 1 'DataBind() Next Catch ex As Exception MsgBox(ex.Message) End Try End If 'BindData(idSelection) End Sub Private Sub ToggleCheckState(ByVal checkState As Boolean) For Each row As GridViewRow In GridView1.Rows Dim cb As CheckBox = row.FindControl("chkDelete") If cb IsNot Nothing Then cb.Checked = checkState End If Next End Sub
-
Hi there! I am having difficulty in deleting a row from a gridview. I would like to delete a row of data in a gridview using checkbox but at the same time would not delete that data from the database. I have tried using deleteRow method but am still struggling. Is there a work-around solution for this? BtnDelete Method Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click If Not IsPostBack Then Dim Row2 As GridViewRow Dim rowCell As String = "" Dim count As Integer = 0 Dim test As Integer = 0 Try For Each row As GridViewRow In GridView1.Rows Dim checkBxText As String = CType(row.FindControl("chkDelete"), CheckBox).Text Row2 = GridView1.Rows(count) rowCell = Row2.Cells(2).Text Dim cb As CheckBox = DirectCast(row.FindControl("chkDelete"), CheckBox) If cb.Checked Then Try 'GridView1.Row(row.RowIndex).Delete() MsgBox(row.RowIndex) GridView1.DeleteRow(row.RowIndex) Catch ex As Exception 'MsgBox(count) GridView1.DataBind() End Try Else End If count += 1 'DataBind() Next Catch ex As Exception MsgBox(ex.Message) End Try End If 'BindData(idSelection) End Sub Private Sub ToggleCheckState(ByVal checkState As Boolean) For Each row As GridViewRow In GridView1.Rows Dim cb As CheckBox = row.FindControl("chkDelete") If cb IsNot Nothing Then cb.Checked = checkState End If Next End Sub
-
Hi there! I am having difficulty in deleting a row from a gridview. I would like to delete a row of data in a gridview using checkbox but at the same time would not delete that data from the database. I have tried using deleteRow method but am still struggling. Is there a work-around solution for this? BtnDelete Method Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click If Not IsPostBack Then Dim Row2 As GridViewRow Dim rowCell As String = "" Dim count As Integer = 0 Dim test As Integer = 0 Try For Each row As GridViewRow In GridView1.Rows Dim checkBxText As String = CType(row.FindControl("chkDelete"), CheckBox).Text Row2 = GridView1.Rows(count) rowCell = Row2.Cells(2).Text Dim cb As CheckBox = DirectCast(row.FindControl("chkDelete"), CheckBox) If cb.Checked Then Try 'GridView1.Row(row.RowIndex).Delete() MsgBox(row.RowIndex) GridView1.DeleteRow(row.RowIndex) Catch ex As Exception 'MsgBox(count) GridView1.DataBind() End Try Else End If count += 1 'DataBind() Next Catch ex As Exception MsgBox(ex.Message) End Try End If 'BindData(idSelection) End Sub Private Sub ToggleCheckState(ByVal checkState As Boolean) For Each row As GridViewRow In GridView1.Rows Dim cb As CheckBox = row.FindControl("chkDelete") If cb IsNot Nothing Then cb.Checked = checkState End If Next End Sub
I think you can simply use datatable for your table manipulation in disconnected environment.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman