Try this
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.Grid td
{
background-color: #eee;
color: black;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
cursor: pointer;
width: 100px;
}
.Grid th
{
background-color: #6C6C6C;
color: White;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
width: 100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" CssClass = "Grid" runat="server" AutoGenerateColumns="false" OnRowDataBound = "OnRowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:BoundField DataField="DOB" HeaderText="Date Of Birth"/>
</Columns>
</asp:GridView>
</form>
</body>
</html>
The above is the html code in which i have take two columns in my GridView
Imports System.Data
Imports System.Drawing
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Name"), New DataColumn("DOB")})
dt.Rows.Add("Raj", "03/01/2013")
dt.Rows.Add("Ravi", "05/12/2013")
dt.Rows.Add("Ram", "04/16/2013")
dt.Rows.Add("Ashok", "05/15/2013")
dt.Rows.Add("Ajay", "05/25/2013")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim dob As Date = e.Row.Cells(1).Text
For Each cell As TableCell In e.Row.Cells
If dob.Month = DateTime.Now.Month Then
cell.BackColor = Color.Red
End If
If dob.Month = DateTime.Now.Month + 1 Then
cell.BackColor = Color.Yellow
End If
If dob.Month = DateTime.Now.Month + 2 Then
cell.BackColor = Color.Orange
End If
Next
End If
End Sub
End Class
The above is the code where i have hardcodedly passed the data to my gridview and on the row_bound event i have compared the month from the gridview Date with the month of the current date