且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET中突出显示gridview中的每一行

更新时间:2022-05-17 03:07:17

您可以在RowDataBound事件中编写必要的逻辑来更改行基于条件的背景颜色,如下所示 -

You can write the necessary logic in RowDataBound event to change row background color based on condition, something like following-
protected void MyGridview_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int ID = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "ID"));

            if (ID == 1 OR ID == 3 OR ID == 4)
            {
                e.Row.Attributes["style"] = "background-color: #008000";
            }
        }        
    }





希望,它有帮助:)



Hope, it helps :)