Hi sat,
Please refer below sample.
HTML
<asp:DataList ID="dlCustomers" RepeatColumns="1" runat="server" OnItemDataBound="dlCustomers_ItemDataBound">
<ItemTemplate>
<table class="table" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>
ID
</th>
<th>
RegNo
</th>
<th>
Status
</th>
</tr>
<tr>
<td>
<%#Eval("ID")%>
</td>
<td>
<%#Eval("RegNo")%>
</td>
<td>
<asp:Label ID="lblStatus" Text='<%#Eval("Status") %>' runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id", typeof(int)), new DataColumn("RegNo", typeof(int)), new DataColumn("status", typeof(string)) });
dt.Rows.Add(1, 10501, "Complete");
dt.Rows.Add(2, 10502, "Pending");
dt.Rows.Add(3, 10503, "Pending");
dt.Rows.Add(4, 10504, "");
dt.Rows.Add(5, 10505, "");
dlCustomers.DataSource = dt;
dlCustomers.DataBind();
}
protected void dlCustomers_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label label = e.Item.FindControl("lblStatus") as Label;
if (label.Text.Trim().ToLower() == "pending")
{
e.Item.BackColor = System.Drawing.Color.Red;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Id", GetType(Integer)), New DataColumn("RegNo", GetType(Integer)), New DataColumn("status", GetType(String))})
dt.Rows.Add(1, 10501, "Complete")
dt.Rows.Add(2, 10502, "Pending")
dt.Rows.Add(3, 10503, "Pending")
dt.Rows.Add(4, 10504, "")
dt.Rows.Add(5, 10505, "")
dlCustomers.DataSource = dt
dlCustomers.DataBind()
End Sub
Protected Sub dlCustomers_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim label As Label = TryCast(e.Item.FindControl("lblStatus"), Label)
If label.Text.Trim().ToLower() = "pending" Then
e.Item.BackColor = System.Drawing.Color.Red
End If
End If
End Sub
Screenshot