Consider we have 3 Grids G1, G2, G3. And we are displaying data in G1 and G2. We will display those records in G3 which are not present in G2 as compared to G1.
Here we are checking first column value of G1 to first column value of G2 and adding records to list as per condition. Here is the code:
- List<int> newLists = new List<int>();
-
-
- foreach (GridViewRow row1 in G1.Rows)
- {
- if (row1.RowType == DataControlRowType.DataRow)
- {
- string gv1Value = row1.Cells[0].Text;
-
- foreach (GridViewRow row2 in G2.Rows)
- {
- if (row2.RowType == DataControlRowType.DataRow)
- {
- string gv2Value = row2.Cells[0].Text;
-
- if (!gv1Value.Contains(gv2Value))
- {
-
- newLists.Add(Convert.ToInt32(gv1Value));
- }
- }
- }
- }
- }
-
- if (newLists.Count > 0)
- {
- G3.DataSource = newLists;
- G3.DataBind();
- }
Hope this Code Snippet will help you.