Hi nauna,
Check this example. Now please take its reference and correct your code.
HTML
C#
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<th>Type</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr><asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder></tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:Label ID="lblplaytype" runat="server" Text='<%#Eval("type") %>'
ForeColor='<%#Eval("type").ToString().ToLower()== "a"?System.Drawing.Color.Red:System.Drawing.Color.Green %>'></asp:Label>
</td>
</ItemTemplate>
</asp:ListView>
VB.Net
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<th>Type</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr><asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder></tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:Label ID="lblplaytype" runat="server" Text='<%#Eval("type") %>'
ForeColor='<%# If(Eval("type").ToString().ToLower() = "a", System.Drawing.Color.Red, System.Drawing.Color.Green) %>'></asp:Label>
</td>
</ItemTemplate>
</asp:ListView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("type");
dt.Rows.Add("a");
dt.Rows.Add("b");
dt.Rows.Add("b");
dt.Rows.Add("a");
ListView1.DataSource = dt;
ListView1.DataBind();
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.Add("type")
dt.Rows.Add("a")
dt.Rows.Add("b")
dt.Rows.Add("b")
dt.Rows.Add("a")
ListView1.DataSource = dt
ListView1.DataBind()
End If
End Sub
Output