gpt4 book ai didi

asp.net - 如何根据其值更改gridview单元格背景颜色

转载 作者:行者123 更新时间:2023-12-02 16:56:39 25 4
gpt4 key购买 nike

我需要更改 gridview 单元格的背景颜色,但它不起作用。

Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
For Each er As GridViewRow In GridView2.Rows
If er.Cells(4).Text = "Formation" Then
er.Cells(4).BackColor = Color.Red
End If
Next
End If
End Sub

如何根据单元格的值更改单元格的背景颜色?

最佳答案

试试这个:

Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(4).Text = "Formation" Then
e.Row.Cells(4).BackColor = Color.Red
End If
End If
End Sub

同时放置一个断点

If e.Row.Cells(4).Text = "Formation" Then

并检查e.Row.Cells(4).Text的值并确保它确实="Formation",也许您需要获取该值Cells(4) 中的标签。

关于asp.net - 如何根据其值更改gridview单元格背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30697449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com