TonyReba
asked on
Change background color at run time DataList
I have the following code to chnage the row color according to a db status, but something to seems to be wrong, I dont get error, but the cells dont change the color..
any ideas?
any ideas?
<asp:DataList ID="DataList1" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataKeyField="Id" DataSourceID="SqlDataSource1" GridLines="Vertical"
oneditcommand="DataList1_EditCommand"
OnUpdateCommand="DataList1_UpdateCommand"
OnCancelCommand="DataList1_CancelCommand" style="font-size: x-small"
Width="16px" Height="16px"
onitemdatabound="DataList1_ItemDataBound" >
.cs
protected void DataList1_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 status = drv.Row["Status"].ToString();
if (status == "Available")
e.Item.BackColor = System.Drawing.Color.LightGreen;
if (status == "Assigned")
e.Item.BackColor = System.Drawing.Color.LightSteelBlue;
if (status == "BR")
e.Item.BackColor = System.Drawing.Color.LightSalmon;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it all looks like it should work. however, just as a test, let's add a "default" background colour...
am suspecting that your conditions are never evaluating to true
protected void DataList1_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 status = drv.Row["Status"].ToString();
if (status == "Available")
e.Item.BackColor = System.Drawing.Color.LightGreen;
else if (status == "Assigned")
e.Item.BackColor = System.Drawing.Color.LightSteelBlue;
else if (status == "BR")
e.Item.BackColor = System.Drawing.Color.LightSalmon;
else
e.Item.BackColor = System.Drawing.Color.Pink;
}
}
am suspecting that your conditions are never evaluating to true
ASKER
Open in new window