ASPxGridView的HtmlDataCellPrepared获取或设置数据绑定后的单元格属性-超级极品

在 ASPxGridView 中动态设置单元格前景色等属性
在 DevExpress 的 ASPxGridView 控件中,您可以通过几种方式在数据绑定后动态设置单元格的前景色。以下是几种常见的方法:
方法1:使用 HtmlDataCellPrepared 事件
这是最常用的方法,可以在单元格渲染前设置其样式:

protected void ASPxGridView_ssjsmd_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)

        {
            if (e.DataColumn.FieldName=="列一")
            {
                if(e.GetValue("列一")!=null)
                {
 string a1 = e.GetValue("列一").ToString();
                if (a1.Contains("回避"))
                {
                    //该单元格显示红色
                    e.Cell.ForeColor = Color.Red;
                   
                }
                }
               
            }
            if (e.DataColumn.FieldName == "列二")
            {
                if (e.GetValue("列二") != null)
                {
string a1 = e.GetValue("列二").ToString();
                if (a1.Contains("回避"))
                {
                    //该单元格显示红色
                    e.Cell.ForeColor = Color.Red;

                }
                }
                
            }
            if (e.DataColumn.FieldName == "列三")
            {
                if (e.GetValue("列三") != null)
                {
 string a1 = e.GetValue("列三").ToString();
                if (a1.Contains("回避"))
                {
                    //该单元格显示红色
                    e.Cell.ForeColor = Color.Red;

                }
                }
               
            }
            if (e.DataColumn.FieldName == "列四")
            {
                if (e.GetValue("列四") != null)
                {
string a1 = e.GetValue("列四").ToString();
                if (a1.Contains("回避"))
                {
                    //该单元格显示红色
                    e.Cell.ForeColor = Color.Red;

                }
                }
                
            }
            if (e.DataColumn.FieldName == "列五")
            {
                if (e.GetValue("列五") != null)
                {
 string a1 = e.GetValue("列五").ToString();
                if (a1.Contains("回避"))
                {
                    //该单元格显示红色
                    e.Cell.ForeColor = Color.Red;

                }
                }
               
            }
        }

渝公网安备 50011902000225号

渝ICP备18008233号-1