title: how to compare two gridview and ignore the sequence of data inside
body: <p>I am working with a program that need to compare between two gridview.</p>
  
  <blockquote>
    <p>So, I have two gridview</p>
    
    <p>The first Gridview have a data that I added manually,</p>
  
  <pre><code>  column 1 | column 2 | column 3 
        a    |     d    |     g
        b    |     e    |     h
        c    |     f    |     j
  </code></pre>
    
    <p>The second gridview data is retrieve from database. The example retrieving result is like this:</p>
  
  <pre><code>  column 1 | column 3 | column 2 
        a    |     g    |     d
        b    |     h    |     e
        c    |     j    |     f
  </code></pre>
    
    <p>Or could be like this:</p>
  
  <pre><code>  column 2 | column 1 | column 3 
        d    |     a    |     g
        e    |     b    |     h
        f    |     c    |     j
  </code></pre>
  </blockquote>
  
  <p>I used this code to retrieve the data from database:</p>
  
  <pre><code>    Protected Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click
      sql = txtQuery.Text
      cmd = New SqlCommand(sql, con)
      drDataReader = cmd.ExecuteReader
      dtDatatable.Load(drDataReader)
      GridView1.DataSource = dtDatatable
      GridView1.DataBind()
      GridView1.Visible = True
  End Sub
  </code></pre>
  
  <p>In short, the second gridview was obtained depends on the user input in txtQuery.text, and I want to compare both gridview and check whether is TRUE or FALSE. If the result is the same without concerning about the sequence of the data just like the table above then display true, if wrong then display false.</p>
  
  <p>EDITED: I tried to store the gridview value into an array and compare the array. The comparison is to check if all the data in arraylist2 is exist in arraylist1 and also if the data in arraylist1 is exist in arraylist2. I tried the first comparison using this code, but it doesn't seem to work.</p>
  
  <pre><code>Protected Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click
      Dim arrayList1 As ArrayList = New ArrayList()
      Dim arrayList2 As ArrayList = New ArrayList()
      Dim arrayList3 As ArrayList = New ArrayList()
      Dim a As Integer
      Dim b As Integer
      For a = 0 To GridView1.Rows.Count - 1 Step 1
          For b = 0 To GridView1.Columns.Count - 1 Step 1
              arrayList1.Add(GridView1.Rows(a).Cells(b).Text)
          Next
      Next
  
      Dim c As Integer
      Dim d As Integer
      For c = 0 To GridView2.Rows.Count - 1 Step 1
          For d = 0 To GridView2.Columns.Count - 1 Step 1
              arrayList2.Add(GridView2.Rows(c).Cells(d).Text)
          Next
      Next
  
      If Not arrayList2.Contains(arrayList1) Then
          MsgBox("True")
      Else
          MsgBox("False")
      End If
  </code></pre>
  
  <p>I don't know why but the above code always display "TRUE".</p>
  
  <p>is there any wrong with the code?
  I think it read the row number instead of the string for each row. </p>
  
  <p>Thanks in advance.</p>