C#gridview颜色提示

2021/9/5 22:09:39

本文主要是介绍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;
                    }
                }
            }
        }

  



这篇关于C#gridview颜色提示的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程