0

i need to compare a gridview with a datatable, and when its matched i need to check a checkbox control the exact row that is matched. so can anyone give me an opinion on this??

currently im using a foreach() and datatable.select(). and the code is here..

 foreach (GridViewRow grdrwCr /*dtrwCr1*/ in grdCr.Rows /*&dtCr1.Rows*/)
        {string TxnNo = grdrwCr.Cells["TxnNo"].ToString();
            string TxnDate = grdrwCr.Cells["TxnDate"].ToString();
            string TxnID = grdrwCr.Cells["TxnID"].ToString();
            string ChequeNo = grdrwCr.Cells["ChequeNo"].ToString();
            string CrAmount = grdrwCr.Cells["lblCrAmount"].ToString();

2 Answers2

0

In the first time when you bind control, you must to print primary key (column with visible = false ) for each row in your gridview.

In the second time when the user select checkbox or row, you take the primary key corresponding with event.

and with primary key ,,, you select yours data in the datatable.

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
0

Just a thought. If you can bind the GridView with dataTable as datasource, then you can merge this 2 datatables and check the row state decide the checkbox logic.

MSDN link for merging 2 datatables - http://msdn.microsoft.com/en-us/library/fk68ew7b.aspx

Already discussed in following link- C# - Merge two DataTables where rows are duplicate

var intersection = table1.AsEnumerable() 
                         .Intersect(table2.AsEnumerable(), DataRowComparer.Default); 
Community
  • 1
  • 1
SSK .NET PRO
  • 126
  • 4