Please refer this code
HTML
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
OnRowDataBound="GridView1_OnRowDataBound" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="30" />
<asp:BoundField DataField="CheckIn" HeaderText="CheckIn DateTime" DataFormatString="{0:dd/MM/yyyy}"
ItemStyle-Width="150" />
</Columns>
</asp:GridView>
Namespaces
using System.Data;
using System.Globalization;
using System.Drawing;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name", typeof(string)),
new DataColumn("CheckIn",typeof(DateTime))});
dt.Rows.Add(1, "10/6/2014 9:13:38 AM");
dt.Rows.Add(2, "10/7/2014 9:16:34 AM");
dt.Rows.Add(3, "10/8/2014 9:11:53 AM");
dt.Rows.Add(4, "10/8/2014 6:03:25 PM");
dt.Rows.Add(4, "10/11/2014 9:17:33 AM");
dt.Rows.Add(4, "10/11/2014 4:50:42 PM");
dt.Rows.Add(4, "10/12/2014 9:09:38 AM");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex != 0)
{
DateTime dt1 = Convert.ToDateTime(this.GridView1.Rows[e.Row.RowIndex - 1].Cells[1].Text, new CultureInfo("en-GB"));
DateTime dt2 = Convert.ToDateTime(e.Row.Cells[1].Text, new CultureInfo("en-GB"));
TimeSpan timeSpan = dt2.Subtract(dt1);
if (timeSpan.TotalHours > 24)
{
e.Row.BackColor = Color.Red;
}
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Name", GetType(String)), New DataColumn("CheckIn", GetType(DateTime))})
dt.Rows.Add(1, "10/6/2014 9:13:38 AM")
dt.Rows.Add(2, "10/7/2014 9:16:34 AM")
dt.Rows.Add(3, "10/8/2014 9:11:53 AM")
dt.Rows.Add(4, "10/8/2014 6:03:25 PM")
dt.Rows.Add(5, "10/11/2014 9:17:33 AM")
dt.Rows.Add(6, "10/11/2014 4:50:42 PM")
dt.Rows.Add(7, "10/12/2014 9:09:38 AM")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub GridView1_OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex <> 0 Then
Dim dt1 As DateTime = Convert.ToDateTime(Me.GridView1.Rows(e.Row.RowIndex - 1).Cells(1).Text, New CultureInfo("en-GB"))
Dim dt2 As DateTime = Convert.ToDateTime(e.Row.Cells(1).Text, New CultureInfo("en-GB"))
Dim timeSpan As TimeSpan = dt2.Subtract(dt1)
If timeSpan.TotalHours > 24 Then
e.Row.BackColor = Color.Red
End If
End If
End If
End Sub
Screenshot