I am trying to change the row color of a DataList Control...
<asp:DataList ID="dlTrades" Width="100%"
RepeatDirection="Horizontal"
RepeatColumns="6" runat="server"
DataSourceID="objTrds"
OnItemDataBound="dlTrades_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td>
<b>
<%# DataBinder.Eval((System.Data.DataRowView)Container.DataItem, "Status") %>
</b>
</td>
</tr>
</table>
<table>
<tr>
<td><%# DataBinder.Eval((System.Data.DataRowView)Container.DataItem, "Hold") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
with the following itemdatabound event:
protected void dlTrades_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
System.Data.DataRowView drv = (System.Data.DataRowView)(e.Item.DataItem);
string hld = (string)drv.Row["Hold"].ToString();
if (hld == "Trade")
{
e.Item.BackColor = System.Drawing.Color.LightGreen;
e.Item.ForeColor = System.Drawing.Color.White;
e.Item.Font.Bold = true;
}
if (hld == "Hold")
{
e.Item.BackColor = System.Drawing.Color.LightGray;
e.Item.ForeColor = System.Drawing.Color.White;
e.Item.Font.Bold = true;
}
System.Data.DataRowView drv2 = (System.Data.DataRowView)(e.Item.DataItem);
string stat = (string)drv2.Row["Status"].ToString();
if (stat == "Open")
{
e.Item.BackColor = System.Drawing.Color.LightGreen;
e.Item.ForeColor = System.Drawing.Color.White;
e.Item.Font.Bold = true;
}
if (stat == "Filled")
{
e.Item.BackColor = System.Drawing.Color.Gold;
e.Item.ForeColor = System.Drawing.Color.White;
e.Item.Font.Bold = true;
}
if (stat == "Closed")
{
e.Item.BackColor = System.Drawing.Color.IndianRed;
e.Item.ForeColor = System.Drawing.Color.White;
e.Item.Font.Bold = true;
}
}
}
The problem is that whatever is the last set of background colors does both rows.. how can I separate the rows so that one row is 'Status' color and one row is 'Hold' Color??
I tried using div tags as a prev post mentioned but divID.Attributes.Add(set style: color) did not compile...
Thanks,
Using a Label Control and expanding it 100% of column width works well for this.