0

我正在尝试检查每行单元格 (3) 中的日期。如果第一个条件为真,我只能获得日期If,其余单元格显示为空白。代码如下。

        For Each row As GridViewRow In GridView1.Rows
            If Not IsDBNull(dr("B1Week").ToString) Then
                e.Row.Cells(3).Text = dr("B1week").ToString
                e.Row.Cells(3).ForeColor = System.Drawing.Color.Blue

            ElseIf DD2 <= Now Then
                e.Row.Cells(3).Text = e.Row.Cells(3).Text & " - OVERDUE"
                e.Row.Cells(3).ForeColor = System.Drawing.Color.Red

            ElseIf DD2 <= Now.AddDays(7) Then
                e.Row.Cells(3).Text = e.Row.Cells(3).Text & " - DUE "
                e.Row.Cells(3).ForeColor = System.Drawing.Color.Green

            End If

        Next row

我希望检查每行中的每个单元格 3 并分配值。任何人都可以帮忙吗?

4

1 回答 1

0

在您的 For Each 循环中,您需要使用 row 变量:

    For Each row As GridViewRow In GridView1.Rows
        If Not IsDBNull(dr("B1Week").ToString) Then
            row.Cells(3).Text = dr("B1week").ToString
            row.Cells(3).ForeColor = System.Drawing.Color.Blue

        ElseIf DD2 <= Now Then
            row.Cells(3).Text = e.Row.Cells(3).Text & " - OVERDUE"
            row.Cells(3).ForeColor = System.Drawing.Color.Red

        ElseIf DD2 <= Now.AddDays(7) Then
            row.Cells(3).Text = e.Row.Cells(3).Text & " - DUE "
            row.Cells(3).ForeColor = System.Drawing.Color.Green

        End If

    Next row
于 2012-12-18T22:15:43.120 回答