Hi Tevin,
Refer below sample.
HTML
<asp:Repeater ID="rptCustomers" runat="server" OnItemDataBound="rptCustomers_ItemDataBound">
<HeaderTemplate>
<table class="table table-striped table-bordered table-hover table-condensed" border="1">
<thead>
<tr>
<th>
Name
</th>
<th>
Next Due Date
</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr id="row">
<td>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</td>
<td>
<asp:Label Text='<%#Eval("Next Due Date")%>' runat="server" ID="lblDate" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody> </table>
</FooterTemplate>
</asp:Repeater>
Code
C#
using System.Data;
using System.Drawing;
VB.Net
Imports System.Data
Imports System.Drawing
Namespaces
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Name", typeof(string)), new DataColumn("Next Due Date", typeof(DateTime)) });
dt.Rows.Add("Mudassar Khan", DateTime.Today);
dt.Rows.Add("John Hammod", DateTime.Today.AddDays(1));
dt.Rows.Add("Suzanne Mathews", DateTime.Today.AddDays(2));
dt.Rows.Add("Robert Schidner", DateTime.Today.AddDays(3));
rptCustomers.DataSource = dt;
rptCustomers.DataBind();
}
}
protected void rptCustomers_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RepeaterItem item = e.Item;
Label lbldate = item.FindControl("lblDate") as Label;
if (Convert.ToDateTime(lbldate.Text) == DateTime.Today)
{
lbldate.BackColor = Color.Red;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Name", GetType(String)), New DataColumn("Next Due Date", GetType(DateTime))})
dt.Rows.Add("Mudassar Khan", DateTime.Today)
dt.Rows.Add("John Hammod", DateTime.Today.AddDays(1))
dt.Rows.Add("Suzanne Mathews", DateTime.Today.AddDays(2))
dt.Rows.Add("Robert Schidner", DateTime.Today.AddDays(3))
rptCustomers.DataSource = dt
rptCustomers.DataBind()
End If
End Sub
Protected Sub rptCustomers_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim item As RepeaterItem = e.Item
Dim lbldate As Label = TryCast(item.FindControl("lblDate"), Label)
If Convert.ToDateTime(lbldate.Text) = DateTime.Today Then
lbldate.BackColor = Color.Red
End If
End If
End Sub
Screenshot