C#gridview颜色提示

 OnRowCreated="gridStatistic_RowCreated

     private void FillUI()
        {
            gridStatistic.DataSource = dtStatistic;
            gridStatistic.DataBind();
        }

 protected void gridStatistic_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                if (dtStatistic != null && dtStatistic.Rows.Count > 0)
                {
                    decimal InfoReward = Convert.ToDecimal(dtStatistic.Rows[e.Row.RowIndex].ItemArray[dtStatistic.Columns.IndexOf("InfoReward")]);
                    decimal InfoMoney = Convert.ToDecimal(dtStatistic.Rows[e.Row.RowIndex].ItemArray[dtStatistic.Columns.IndexOf("InfoMoney")]);
                    if (InfoMoney > InfoReward)
                    {
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }


---------------或:---decimal数值对比--
 protected void gridStatistic_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                if (dtStatistic != null && dtStatistic.Rows.Count > 0)
                {
                    decimal InfoReward  = Convert.ToDecimal(dtStatistic.Rows[e.Row.RowIndex].ItemArray[dtStatistic.Columns.IndexOf("InfoReward")]);
                    decimal InfoMoney = Convert.ToDecimal(dtStatistic.Rows[e.Row.RowIndex].ItemArray[dtStatistic.Columns.IndexOf("InfoMoney")]);
                    decimal cs = InfoMoney - InfoReward;
                    if (cs>0)
                    {
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }
--------------
 protected void gridStatistic_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                if (dtStatistic != null && dtStatistic.Rows.Count > 0)
                {
                    string InfoMoney="";
                    decimal InfoReward  = Convert.ToDecimal(dtStatistic.Rows[e.Row.RowIndex].ItemArray[dtStatistic.Columns.IndexOf("InfoReward")]);
                    InfoMoney = Convert.ToString(dtStatistic.Rows[e.Row.RowIndex].ItemArray[dtStatistic.Columns.IndexOf("InfoMoney")]);
                    if (InfoMoney == "")
                        InfoMoney ="0";

                    if (Convert.ToDecimal(InfoMoney) > InfoReward)
                    {
                        e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }

  

posted @ 2021-09-05 20:25  刘贵庆  阅读(46)  评论(0编辑  收藏  举报