Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Need to delete row in gridview but must not affect that row in the database.

Need to delete row in gridview but must not affect that row in the database.

Scheduled Pinned Locked Moved ASP.NET
databasequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    renoma
    wrote on last edited by
    #1

    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

    M M 2 Replies Last reply
    0
    • R renoma

      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

      M Offline
      M Offline
      Meetu Choudhary
      wrote on last edited by
      #2

      Have you tried deleting the row from the datatable you bounded the grid and don't save the datatable to the database back. just after delting the data from thedatatable rebind the grid.

      Thanks and Regards Meetu Choudhary My Web || My Blog || My Forums

      1 Reply Last reply
      0
      • R renoma

        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

        M Offline
        M Offline
        Md Marufuzzaman
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups