Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a gridview ,it has some rows with the same id ,i want to find the same ids and hide one of them
help me plz
Updated 28-Jul-18 23:10pm

What about never add duplicate to gridview in the first place ?
Share this answer
faezeh66 29-May-11 4:42am    
first i bind it from database
then i merge datatable to it from another place
now i want to show not duplicated row
Kim Togo 29-May-11 7:00am    
If you use .NET 3 and up. You can use Linq to make a distinct on a value?
Abhinav S 29-May-11 8:35am    
Good approach. 5.
Kim Togo 29-May-11 8:44am    
Try to filter this duplicate id / row in the query itself.
This would be the most optimized way of getting rid of duplicates.
Share this answer
Kim Togo 29-May-11 8:44am    
And the same to you. My 5.
Abhinav S 29-May-11 10:07am    
Thank you.
It's not a good idea. Better handle those things in DataSource. Filter the data in DataSource(DataTable or something) & then bind it to GridView.

For your information
DataView.RowFilter Property[^]
Share this answer
Kim Togo 29-May-11 8:46am    
My 5 for the .RowFilter.
Function findIDInGrid(ByVal array As ArrayList, ByVal s As String) As Integer
      Dim digit As Integer = -1
      For Each obj As Object In array
          If obj.ToString() = s Then
              digit = array.IndexOf(obj)
              Exit For
          End If

      Return digit
  End Function
  Protected Sub grdGoods_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdGoods.PreRender

          Dim array As New ArrayList

          For Each row As GridViewRow In grdGoods.Rows
              Dim rug_Id As Label = CType(row.FindControl("rug_Id"), Label)
              If findIDInGrid(array, rug_Id.Text) <> -1 Then
                  grdGoods.Rows(findIDInGrid(array, rug_Id.Text)).Visible = False
              End If
              End If
end sub
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900