Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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
Asp.net 如果Gridview行在同一日期是白色,然后是灰色,请更改该行的颜色_Asp.net_Vb.net_Gridview - Fatal编程技术网

Asp.net 如果Gridview行在同一日期是白色,然后是灰色,请更改该行的颜色

Asp.net 如果Gridview行在同一日期是白色,然后是灰色,请更改该行的颜色,asp.net,vb.net,gridview,Asp.net,Vb.net,Gridview,我需要在动态网格视图上有三种颜色,一种是白色,另一种是灰色,但如果它在同一日期 如果未找到上一个日期,则显示为红色 我的意思是: Name Checkin Checkout Branch 450 10/6/2014 9:13:38 AM 10/6/2014 6:01:50 PM branch0 white 450 10/7/2014 9:16:34 AM 10/7/2014 6:44:21 PM branch

我需要在动态网格视图上有三种颜色,一种是白色,另一种是灰色,但如果它在同一日期 如果未找到上一个日期,则显示为红色 我的意思是:

Name        Checkin           Checkout              Branch 
450 10/6/2014 9:13:38 AM    10/6/2014 6:01:50 PM    branch0  white
450 10/7/2014 9:16:34 AM    10/7/2014 6:44:21 PM    branch0 gray
450 10/8/2014 9:11:53 AM                            branch0 white
450 10/8/2014 6:03:25 PM                            branch0 white
450 10/11/2014 9:17:33 AM   10/11/2014 6:29:16 PM   branch0 red
450 10/11/2014 4:50:42 PM                           branch0 red
450 10/12/2014 9:09:38 AM                           branch0 white
这就是我的观点

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataSourceID="SqlDataSource2" 
            BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" 
            CellPadding="3" CellSpacing="2" HorizontalAlign="Center" Width="602px">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name" 
                    SortExpression="Name" />
                <asp:BoundField DataField="Checkin" HeaderText="Checkin" 
                    SortExpression="Checkin" ReadOnly="True" />
                <asp:BoundField DataField="Checkout" HeaderText="Checkout" 
                    SortExpression="Checkout" ReadOnly="True" />
                <asp:BoundField DataField="MachineAlias" HeaderText="Branch" 
                    SortExpression="MachineAlias" />
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView> 
我搜索后得到了这个代码

Dim found As Boolean
    Dim dt As DateTime
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Checkout")) Then
                dt = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "Checkout")).Date


            End If

            If e.Row.RowIndex > 0 And found = False Then
                e.Row.BackColor = Drawing.Color.Red
            End If
            found = Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Checkout"))
        End If
    End Sub
但它给了我错误

当我尝试@Zack先生的代码时,我出现了这个错误

尝试使用此

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles        GridView1.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then

        Dim arg1 As Date = Date.Parse(e.Row.Cells(1).Text)
        Dim arg2 As Date = Date.Parse(iif(isDate(e.Row.Cells(2).Text),e.Row.Cells(2).Text,"1/1/1900"))

        If arg1 = arg2 Then
            e.Row.BackColor = Drawing.Color.Red
        End If

    End If
End Sub

非常确定您可以使用RowDataBound事件来比较这两列,并在日期匹配时突出显示它们。您需要将来自单元格的数据格式化为mm/dd/yyyy,并删除时间,以使其精确匹配。我想给你举个例子,但我不是坐在有编译器的电脑前,也不想给你难看的代码。如果你谷歌它,你应该能够找到它上的东西。错误线是因为它需要E.ROW.ROWTYPE,你只是在它的中间有一个“R”。它还处理GridView1.DataBinding,需要是GridView1.RowDataBound首先让我感谢你,我为你编辑我的帖子我有一个错误,并确保如果我尝试此代码,我将有三种颜色的W和G和RTry更改为我上面的建议,抱歉,如果语法被提升,我现在正在从内存中执行此操作。。。
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles        GridView1.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then

        Dim arg1 As Date = Date.Parse(e.Row.Cells(1).Text)
        Dim arg2 As Date = Date.Parse(iif(isDate(e.Row.Cells(2).Text),e.Row.Cells(2).Text,"1/1/1900"))

        If arg1 = arg2 Then
            e.Row.BackColor = Drawing.Color.Red
        End If

    End If
End Sub