Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:24:10+00:00 2026-06-11T01:24:10+00:00

I am trying to delete a row from a gridview (based on a condition)

  • 0

I am trying to delete a row from a gridview (based on a condition) and then add than row to another gridview inside of the “master” gridview’s RowDataBound event. Originally I did not know that in order to call .DeleteRow(i) you needed to have an “ondelete” event handler. However, since all the gridview’s .DeleteRow method does is call this event handler, I am confused as to how to use it. Can someone please help point me in the right direction?

Protected Sub grdProduct_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdProduct.RowDataBound

    ' Grey out expired products
    Dim row As GridViewRow
    row = e.Row

    Dim incomingDate As String
    Dim incomingStatus As String = ""

    incomingDate = row.Cells(3).Text.ToString()
    incomingStatus = row.Cells(5).Text.ToString()

    If (e.Row.RowType <> DataControlRowType.DataRow) Then
        Exit Sub
    End If

    Try
        Dim expDate As Date = incomingDate
        If (expDate < DateTime.Today Or incomingStatus.Equals("D")) Then

            'Create object for RowValues
            Dim RowValues As Object() = {"", "", "", "", "", ""}

            'Create counter to prevent out of bounds exception
            Dim i As Integer = row.Cells.Count

            'Fill row values appropriately
            For index As Integer = 0 To i - 1
                RowValues(index) = row.Cells(index).Text
            Next

            'create new data row
            dProdRow = dProdtable.Rows.Add(RowValues)
            dProdtable.AcceptChanges()

            grdProduct.DeleteRow(e.Row.RowIndex)
        End If
    Catch ex As Exception
    End Try
End Sub

Protected Sub grdProduct_Delete(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles grdProduct.RowDeleting
    'Not sure what to do here
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:24:12+00:00Added an answer on June 11, 2026 at 1:24 am

    The best way to do this is to manipulate this at the datasource level rather than manipulating the UI components themselves.

    For example:

    if(!IsPostback)
    {
        DataTable one  = ...
        DataTable two = ...
    
        var removeRows = (from c in one.AsEnumerable()
                         where c.Field<DateTime>("incomingDate")< incomingDate || 
                               c.Field<string>("incomingStatus")=="D"
                         select c).ToList();
    
       for(var item in removeRows)
       {
           two.ImportRow(item);
       }
       //now delete from initial table
       foreach(var item in removeRows)
       {
           one.Rows.Remove(item);
       } 
    
       //Now bind both grids
       grid1.DataSource=one;
       grid1.DataBind();
       grid2.DataSource=two;
       grid2.DataBind();
    
    }
    

    Update – Sample toy program in VB.NET Hopefully you can adapt it to your situation.

    Sub Main
        Dim one As New DataTable()
        one.Columns.Add("one", GetType(Integer))
        For i As Integer = 0 To 9
            Dim r As DataRow = one.NewRow()
            r.ItemArray = New Object() {i}
            one.Rows.Add(r)
        Next
    
        Dim two As New DataTable()
        two.Columns.Add("one", GetType(Integer))
        For i As Integer = 0 To 9
            Dim r As DataRow = two.NewRow()
            r.ItemArray = New Object() {i}
            two.Rows.Add(r)
        Next
        Dim removeRows = (From c In one.AsEnumerable() Where c.Field(Of Integer)("one") = 5).ToList()
    
        For Each item As DataRow In removeRows
            two.ImportRow(item)
        Next
    
        For Each item As DataRow In removeRows
            one.Rows.Remove(item)
        Next
    
    End Sub
    

    I just realized that you are using VB.NET. You should be able to translate the above from C# to VB.NET. The general idea is there, anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to delete the selected row in a gridview from the datatable but
I am trying to find a row and then delete that row from a
I am trying to delete rows from datagridview, when the user selects any row
I'm trying to remove a row from my gridview manually, because for some reason,
I'm trying to simply delete a full row from my SQL Server database table
I'm trying to delete several rows from tblOrderAA and one row from tblProInfo :(look
I'm trying to delete a row from my table view and so far have
I am trying to delete a row from a table but i have three
I'm trying to delete a row from a DataGridView I use two types of
I'm simply trying to delete a row from a DataGridView. Basically, the first column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.