I am trying to change the colour of a div inside a repeater on the itemdatabound event. I have tried using a panel inside the itemdatabound like so;
protected void rptLocations_ItemDataBound(object sender, RepeaterItemEventArgs e)
then inside
Panel cblock = e.Item.FindControl("pnlColour") as Panel;
cblock.Style.Add("background", rndColour);
but this throws an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
I'd rather use a div that a panel anyway.
Is there any way to change the colour of a div from the itemdatabound event?
Thanks in advance!
I managed to fix this using HTMLCONTROLS
I use HtmlGenericControl to set the style attribute.
((HtmlGenericControl)(e.Item.FindControl("divColour"))).Attributes["style"] += ("background:" + rndColour + ";)");
Simple and effective!