0

我有这个 C# 事件处理程序,它假设根据列表视图的值更改文本的颜色

这是代码:

protected void YourListView_Load(object sender, EventArgs e)
{
Label theTWALabel;
int theTWAValue;
foreach (ListViewItem item in YourListView.Items)
{
    theTWALabel = (Label)item.FindControl("TWALabel");
    theTWAValue = Convert.ToInt32(theTWALabel.Text);
    if (theTWAValue >= 0)
    {
        if (theTWAValue < 90)
            theTWALabel.ForeColor = System.Drawing.ColorTranslator.FromHtml("YellowThis");
        else
            theTWALabel.ForeColor = System.Drawing.Color.Red;
    }
}
}

这是列表视图行:

<asp:ListView id="YourListView"  runat="server" DataSourceID="SqlDataSource3" OnLoad="YourListView_Load" EnableViewState="False">

这是我的列表视图代码:

<asp:ListView id="YourListView"  runat="server" DataSourceID="SqlDataSource3" OnLoad="YourListView_Load" EnableViewState="False">       
    <ItemTemplate>
        Plant Name:
        <asp:Label id="PlantLabel" runat="server" Text='<%# Eval("Plant") %>' />
        <br />
        Department #:
        <asp:Label id="column1Label" runat="server" Text='<%# Eval("column1") %>' />
        <br />
        Department Name:
        <asp:Label id="GroupLabel" runat="server" Text='<%# Eval("Group") %>' />
        <br />
        Job Code:
        <asp:Label id="Job_CodeLabel" runat="server" Text='<%# Eval("Job_Code") %>' />
        <br />
        TWA:
        <asp:Label id="TWALabel"   runat="server" Text='<%# Eval("TWA") %>' />
        <br />
        Job Classification:
        <asp:Label id="Job_ClassificationLabel" runat="server" Text='<%# Eval("Job_Classification") %>' />
        <br />
        Job Function:
        <asp:Label id="Job_FunctionLabel" runat="server" Text='<%# Eval("Job_Function") %>' />
        <br />
        Job Description:
        <asp:Label id="Job_DescriptionLabel" runat="server" Text='<%# Eval("Job_Description") %>' />
        <br />
        <br />
    </ItemTemplate>
<LayoutTemplate>
    <div id="itemPlaceholderContainer" runat="server"  style="font-family: Verdana, Arial, Helvetica, sans-serif; text-align:center; border:3em; border-color:black;">
    <span runat="server" id="itemPlaceholder" />
    </div>
</LayoutTemplate>
</asp:ListView>

问题是虽然它会正确输出我的列表视图值,但颜色都没有改变,我不知道为什么。任何帮助都会很棒

编辑:可能是因为我的布局模板控制了所有样式吗?

4

0 回答 0