Hi Nadeem,
If you are saving registration date in database. So you can compare it with current DateTime. For that you can use it by two way you can get current date from database As GetDate() or from code you can get it by DateTime.Now. And Compare it by shown below sample code in DataList ItemDataBound Event So you can set the color of row as per your need.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindDataList();
}
}
private void BindDataList()
{
string cns = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlConnection con = new SqlConnection(cns);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Get_EmployeesDetails";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
dlEmployee.DataSource = ds;
dlEmployee.DataBind();
con.Close();
}
protected void dlEmployee_ItemDataBound(object sender, DataListItemEventArgs e)
{
DateTime registartionDate = Convert.ToDateTime((e.Item.FindControl("lblRegistartionDate") as Label).Text);
DateTime currentdate = DateTime.Now;
// or
//DateTime currentdate = Convert.ToDateTime((e.Item.FindControl("lblCurrentdate") as Label).Text);
TimeSpan t = currentdate.Subtract(registartionDate);
if (t.Days >= 1 || t.Hours >= 1)
{
(e.Item.FindControl("tbl") as System.Web.UI.HtmlControls.HtmlTable).BgColor = "Red";
}
else if (t.Minutes >= 30)
{
(e.Item.FindControl("tbl") as System.Web.UI.HtmlControls.HtmlTable).BgColor = "Orange";
}
else
{
}
}
HTML
<asp:DataList ID="dlEmployee" runat="server" RepeatColumns="3" RepeatLayout="Table"
OnItemDataBound="dlEmployee_ItemDataBound">
<ItemTemplate>
<table id="tbl" runat="server">
<tr>
<th width="200px">
<asp:Label ID="lblFirstName" Text='<% #Eval("FirstName") %>' runat="server" />
<asp:Label ID="lblLastName" Text='<% #Eval("LastName") %>' runat="server" /><br />
<asp:Label ID="lblBirthDate" Text='<% #Eval("BirthDate") %>' runat="server" /><br />
<asp:Label ID="lblRegistartionDate" Text='<% #Eval("RegdDate") %>' runat="server" /><br />
<asp:Label ID="lblCurrentdate" Text='<% #Eval("CurrentDate") %>' runat="server" /><br />
</th>
</tr>
<tr>
<td align="center">
<asp:Label ID="lblCity" Text='<% #Eval("City") %>' runat="server" />
<br />
<asp:Label ID="lblCountry" Text='<% #Eval("Country") %>' runat="server" />
<asp:Label ID="lblstatus" Text='<% #Eval("Status") %>' runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>