【问题标题】:highlight gridview cell by header and row values按标题和行值突出显示gridview单元格
【发布时间】:2026-02-02 09:15:01
【问题描述】:

我有一个 gridview,我能够根据字段名称和该列中单元格的标准突出显示一个单元格。现在我想做同样的事情,但也要考虑第二列的行值。下面的例子


性别 |零件号 |小 |中 |大的
男士 | C-888-TVN | 5 | 6 | 9
男士 | C-777-TV4 | 7 | 7 | 8

因此,如果我想突出显示 C-777-TV4 行和中号下的“7”,我将如何执行这两个标准。这不是基于数字值标准,仅基于标题“Medium”的名称和部件号行“C-777-TV4”中的字符串值。

这是我收到超出范围错误的新代码:

Protected Sub gridStock_HtmlRowPrepared(sender As Object, e As ASPxGridViewTableRowEventArgs) Handles gridStock.HtmlRowPrepared If e.RowType <> GridViewRowType.Data Then Return End If Dim name As String = e.GetValue("CorePN").ToString() If name = "777-M-MBL" Then e.Row.Cells(10).BackColor = System.Drawing.Color.Red End If End Sub

在 e.Row.Cells(10).Backcolor 处得到错误

【问题讨论】:

  • row.Cell[3]怎么样?
  • 我如何声明获取带有 C-777-TV4 行的行。然后我可以检索第三列。

标签: asp.net vb.net gridview


【解决方案1】:

我需要查看您的更多代码。这是我的想法:

If row.Cell(1).Text = "C-777-TV4" Then
     e.Row.Cells(5).BackColor = System.Drawing.Color.Cyan
End If

【讨论】:

  • 感谢您的回复。 `Sub gridStock_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Cells(5).Text = "777-M-CIT" e.Row.Cells(5 ).BackColor = System.Drawing.Color.Cyan End If End Sub'
  • 这确实有道理,但我仍然没有看到任何区别。我尝试同时使用 rowcreated 事件和 rowdatabound 事件,但在我的场景中都不起作用。
  • @SouthernGentleman 如果您可以发布所有代码,我想我可以提供更多帮助。
  • Protected Sub gridStock_RowCreated(sender As Object, e As ASPxGridViewTableRowEventArgs) If e.RowType = DataControlRowType.DataRow Then If e.Row.Cells(1).Text = "C-777-TV4" Then e .Row.Cells(5).BackColor = System.Drawing.Color.Red End If End If End Sub '我对 rowcreated 和 rowdatabound 事件使用了相同的逻辑
  • 你用过调试器吗?我相信 rowdatabound 是存放您的代码的正确位置。
最近更新 更多