比较2个gridviews并从gv2更新gvl

时间:2016-11-17 06:51:00

标签: c# asp.net

我想将oldgridview与newgridview进行比较,并从oldgridview usinf asp.net和c#

更新newgridview

任何人都可以支持我

感谢

1 个答案:

答案 0 :(得分:0)

protected void Button2_Click(object sender, EventArgs e)
    {
        DataTable src1 = gv1.DataSource as DataTable;
        DataTable src2 = gv2.DataSource as DataTable;
        int index1 = 0;

    foreach (DataRow row1 in src1.Rows)
    {
        foreach (DataRow row2 in src2.Rows)
        {
            int index2 = 0;
            bool duplicateRow  = true;
            for (int cellIndex = 0; cellIndex < row1.ItemArray.Count(); cellIndex++)
            {
                if (!row1.ItemArray[cellIndex].Equals (row2.ItemArray[cellIndex].ToString()))
                {
                    duplicateRow  = true;
                    break;
                }
            }

            if (duplicateRow)
            {
                gv1.Rows[index1].DefaultCellStyle.ForeColor  = Color.Red;
            }

            index2++;
        }
        index1++;
    }
}