首页 > 解决方案 > 如何根据它的字段值设置行颜色。来自asp.net中的客户端

问题描述

我正在使用网格视图来显示一个表格,并使用 onRowDataBound 来执行一个根据字段值设置颜色的函数

函数定义是这样的

    {
        e.Row.Cells[3].Visible = false;
        if (e.Row.Cells[3].Text == "0")
            {
                e.Row.ForeColor = System.Drawing.Color.Red;

            }
    }

我想知道如何从客户端而不是服务器端完成此操作。

标签: javascriptjqueryhtmlasp.netasp.net-mvc

解决方案


为客户端找到了这个基本示例

尝试调整它以使用视图中的数据并添加我猜你可以通过 css 放置颜色。

<div>
    <table>
        <tr>
            <td style="width: 100px">StuId
            </td>
            <td style="width: 150px">StuName
            </td>
            <td style="width: 100px">Course
            </td>
        </tr>
    </table>
    <asp:GridView AutoGenerateColumns="false" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound" ID="GridView1" runat="server">
        <Columns>
            <asp:BoundField DataField="StuId" HeaderText="StuId" ItemStyle-Width="100px" />
            <asp:BoundField DataField="StuName" HeaderText="StuName" ItemStyle-Width="150px" />
            <asp:BoundField DataField="Course" HeaderText="Course" ItemStyle-Width="100px" />
        </Columns>
    </asp:GridView>
</div>

文章:https ://www.codeproject.com/Articles/249155/Rows-and-Columns-Merging-in-ASP-NET-GridView-Contr


推荐阅读