在gridview Optimal Way中查找重复的列值
本文关键字:查找 gridview Optimal Way | 更新日期: 2023-09-27 18:21:10
我想知道网格视图中不同行的两个单元格是否具有相同的值。我使用了这个代码,但对于数百万条记录来说,它需要很多时间。你能告诉我一个最佳的方法吗?
有人能给我一个最佳的方式吗?
grv中缺少-1。Rows.Count在语句的"otherRow"中。
public void HighlightDuplicate(GridView grv)
{
//use the currentRow to compare against
for (int currentRow = 0; currentRow < grv.Rows.Count - 1; currentRow++)
{
GridViewRow rowToCompare = grv.Rows[currentRow];
//specify otherRow as currentRow + 1
//This forloop loops over more rows then exist
for (int otherRow = currentRow + 1; otherRow < grv.Rows.Count -1; otherRow++)
{
GridViewRow row = grv.Rows[otherRow];
bool duplicateRow = true;
//compare cell ENVA_APP_ID between the two rows
if (!rowToCompare.Cells["ENVA_APP_ID"].Text.Equals(row.Cells["ENVA_APP_ID"].Text))
{
duplicateRow = false;
break;
}
//highlight both the currentRow and otherRow if ENVA_APP_ID matches
if (duplicateRow)
{
rowToCompare.BackColor = System.Drawing.Color.Red;
}
}
}
}