c# - Set style properties to a div in listview -
i have page listview, has div. div has different background color according database info:
<asp:listview id="lvwpostart" runat="server" datasourceid="odsadvanced" groupitemcount="3" onitemdatabound="lvwpostart_itemdatabound"> <emptydatatemplate> <p>no matches.</p> </emptydatatemplate> <layouttemplate> <table style="border: none"> <asp:placeholder id="groupplaceholder" runat="server"></asp:placeholder> </table> </layouttemplate> <grouptemplate> <tr> <asp:placeholder runat="server" id="itemplaceholder"></asp:placeholder> </tr> </grouptemplate> <itemtemplate> <td> <!--heeeeeeeere's div!!! --> <div id="divcontainer" class="icondetail" runat="server" style='background-color:<%# eval("colorfondo") %>'><!-- here goes custom color --> <div class="innerbox"> <asp:image runat="server" id="img_post" imageurl='<%# eval("imagethumbnail") %>' cssclass="staticimage" /> </div> </div> </td> </itemtemplate> </asp:listview>
however not receiving color. objectdatasource has following dataobjecttypename:
public class myimage { string colorfondo { get; set; } string imagethumbnail { get; set; } }
here tried far:
try #1: set databind directly on div style.
<div id="divcontainer" class="icondetail" runat="server" style='background-color:<%# eval("colorfondo") %>'>
try #2: set information on code behind using property itemdatabound
protected void lvwpostart_itemdatabound(object sender, listviewitemeventargs e) { listviewdataitem dataitem = (listviewdataitem)e.item; if (e.item.itemtype == listviewitemtype.dataitem) { htmlgenericcontrol divcont = (htmlgenericcontrol)e.item.findcontrol("divcontainer"); divcont.style.add("background-color", "#ffffff"); //how can info dataclass assign property???? } }
my question is, how can assign background-color div?
either this
datarowview rowview = (datarowview)dataitem.dataitem; divcont.style.add("background-color", rowview["colorfondo"].tostring());
or this
var myimg = e.item.dataitem myimage; divcont.style.add("background-color", myimg.colorfondo);
Comments
Post a Comment