Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

1 solution

You can do this in the RowDataBound event code.

For e.g.

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;
            }
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900