我正在尝试更改 DataList 控件的行颜色...
<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>
使用以下 itemdatabound 事件:
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;
}
}
}
问题是,无论最后一组背景颜色是什么,两行都是..如何分隔行,以便一行是“状态”颜色,一行是“保持”颜色?
我尝试使用 div 标签作为前面提到的帖子,但 divID.Attributes.Add(set style: color) 没有编译...
谢谢,