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