根据月份以不同的颜色显示GridView中的记录

根据月份以不同的颜色显示GridView中的记录

本文介绍了根据月份以不同的颜色显示GridView中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个GridView,我在其中显示了许多记录。我的GridView中有一个名为StartDate的字段。现在,我希望能够根据StartDate中的月份以不同的颜色显示记录。例如,如果StartDate是在三月份,那么三月份输入的所有记录都应该是绿色,如果StartDate是四月份,那么那个月的所有记录都应该是蓝色。我怎么能实现这个目标?我是我猜我可能不得不使用CSS,但我不是很流利。任何人都可以帮我解决这个问题吗?

I have a GridView on my webpage in which I am displaying a number of records.I have a field in my GridView called StartDate. Now, I want to be able to display the records in a different colour according to the month in the StartDate. For e.g, if the StartDate is in March,then all the records entered in March should be in Green and if the StartDate is in April, then all the records for that month should be in Blue.How can I achieve this?I''m guessing that I might have to use CSS, but I''m not very fluent in it.Can anyone please help me in solving this?

推荐答案

Protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[month].Text == "March")
            {
                e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
            }
        }
    }


这篇关于根据月份以不同的颜色显示GridView中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:56