I have a listview and in It's ItemTemplate, a asp:panel which includes some controls. I need to apply three different css class to the asp:panel, depending on value of one of the controls in my asp:panel.
here's my code:
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
HiddenField type = (HiddenField)e.Item.FindControl("valueOfAd_type");
HiddenField paid = (HiddenField)e.Item.FindControl("valueOfPayment");
Panel ThePanel = (Panel)e.Item.FindControl("Panel1");
if ( paid.Value == "2")
{
if (type.Value == "1") //First condition
{
ThePanel.Attributes.Add("class", "whiteBackground");
}
else if (type.Value == "2") //Second condition
{
ThePanel.Attributes.Add("class", "redBackground");
}
}
else //third condition
{
ThePanel.Attributes.Add("class", "blueBackground");
}
}
}
Problem is, no matter which condition occurs, always the last css class will be apply to all of my asp:panels. now my question is how to apply different css classes to asp:panels in different ItemTemplate?