如何突出显示重复的列?

How to highlight duplicate columns?

提问人:rh208 提问时间:11/8/2023 最后编辑:LarsTechrh208 更新时间:11/8/2023 访问量:35

问:

这就是我到目前为止所拥有的,但我只是对它的工作原理感到困惑。

protected void GridView1_PreRender(object sender, EventArgs e)
{
  HashSet<string> uniqueValues = new HashSet<string>();
  foreach (GridViewRow row in GridView1.Rows)
  {
    // checking duplicate staring at column 1
    string cellText = row.Cells[1].Text;
    // Check if we've already seen this value
    if (uniqueValues.Contains(cellText)) 
    {
      row.Cells[0].CssClass = "duplicate-highlight";
      // This value is a duplicate, apply a CSS class
      // need to add duplicate file to css file standardDesign.cs
    }
    else
    {
      // It's not a duplicate, add it to the set of seen values
      uniqueValues.Add(cellText); 
    }
  }
}

我试图让它突出显示重复的列。

C# SQL asp.net

评论

1赞 LarsTech 11/8/2023
代码是否有效,你问它为什么有效?
0赞 Ted 11/8/2023
你在这里有什么问题?我很困惑
0赞 rh208 11/8/2023
我从软件开发人员那里得到了帮助来回答这个问题,但我想知道代码是做什么的,以及它是否正确地向我的老板展示。我在电子表格中查找行的重复值并突出显示它们。
0赞 LarsTech 11/8/2023
令人困惑的部分是什么?如果您不了解这种类型的集合,也许可以查找 a 是什么。HashSet
0赞 AminM 11/9/2023
请澄清您的具体问题或提供其他详细信息以准确说明您的需求。正如目前所写的那样,很难确切地说出你在问什么。

答: 暂无答案