Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 网格视图中循环中的If语句_Vb.net_Loops_Gridview_For Loop - Fatal编程技术网

Vb.net 网格视图中循环中的If语句

Vb.net 网格视图中循环中的If语句,vb.net,loops,gridview,for-loop,Vb.net,Loops,Gridview,For Loop,我试图检查每行单元格(3)中的日期。我只能在第一个条件为真时获取日期,如果条件为真,则其余单元格显示为空。代码如下 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.

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

        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
将每一行作为GridView1.Rows中的GridViewRow进行

如果不是IsDBNull(dr(“B1Week”).ToString),则
e、 Row.Cells(3).Text=dr(“B1week”).ToString
e、 行.单元格(3).前景色=System.Drawing.Color.Blue

ElseIf DD2在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
将每一行作为GridView1.Rows中的GridViewRow进行

如果不是IsDBNull(dr(“B1Week”).ToString),则
row.Cells(3).Text=dr(“B1week”).ToString
行.单元格(3).前景色=System.Drawing.Color.Blue

ElseIf DD2可以告诉我怎么做,因为目前正在显示第一个if条件if true。如果第一个if为false,则单元格显示为空白。您看过上面的代码了吗?我已经对它进行了编辑,将e.Row.Cells(3)更改为Row.Cells(3)。。。