0
我想改變我的GridView行的顏色conditionaly沒有改變標題顏色變化顏色沒有改變標題顏色
這裏是我的數據綁定功能
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
DateTime Kbl = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "HrsKbl"));
foreach (TableCell cell in e.Row.Cells)
{
if (Kbl == DateTime.Now)
{
cell.BackColor = Color.Yellow;
}
if (Kbl > DateTime.Now)
{
cell.BackColor = Color.Green;
}
if (Kbl < DateTime.Now)
{
cell.Backcolor = Color.Red;
}
}
}
,這裏是我的GridView
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" DataKeyNames="Katalog" CssClass="myGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnPageIndexChanging="exportGrdVw_PageIndexChanging" OnRowDataBound="OnRowDataBound">
<AlternatingRowStyle BackColor="White" CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="No" HeaderStyle-Font-Italic="true">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<HeaderStyle Font-Italic="True" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ID Pinjam" HeaderStyle-Font-Italic="true">
<ItemTemplate>
<asp:Label ID="LabelID" runat="server" Text='<%#Eval("IDPinjam") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Italic="True" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Katalog" HeaderStyle-Font-Italic="true">
<ItemTemplate>
<asp:Label ID="LabelKatalog" runat="server" Text='<%#Eval("Katalog") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Italic="True" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Kbl" HeaderStyle-Font-Italic="true" Visible="false">
<ItemTemplate>
<asp:Label ID="LabelKbl" runat="server" Text='<%#Eval("HrsKbl") %>' Visible="false"></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Italic="True" />
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Italic="true">
<ItemTemplate>
<asp:LinkButton ID="LinkEdit" runat="server" CssClass="myButton" Text="Kembalikan" OnClick="LinkEdit_Click"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Font-Italic="True" />
</asp:TemplateField>
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
當我運行它時,我的gridview標題始終其顏色更改爲「紅」得就像我行的數據綁定