当特定字符出现在网格视图中时,下划线单元格值

时间:2019-04-28 08:52:58

标签: c# asp.net gridview

我必须检查QUALITY的值是D还是E的条件,然后在网格视图中对其下划线。如何在ItemTemplate中做到这一点?

<asp:TemplateField HeaderText="TOTAL QUALITY">
    <ItemTemplate>
        <%# Eval("QUALITY").ToString() == "D" %>
    </ItemTemplate>
</asp:TemplateField>

1 个答案:

答案 0 :(得分:0)

在.aspx文件中更改设计,例如

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:TemplateField HeaderText="TOTAL QUALITY">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("QUALITY")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

.cs文件中的

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label Label1 = (Label)e.Row.FindControl("Label1");

        if (DataBinder.Eval(e.Row.DataItem, "QUALITY").ToString().ToUpper() == "D" || DataBinder.Eval(e.Row.DataItem, "QUALITY").ToString().ToUpper() == "E")
        {
            Label1.Style.Add("text-decoration", "underline");
        }
    }
}

您可以添加更多CSS样式来美化标签。