0

I have got a listview which is styled with css but dosent work.Am I missing something here.

<asp:ListView ID="msg_list" runat="server">
   <ItemTemplate>
     <tr class="myitem">
        <td> <asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /> </td>
     </tr>
     <%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
   </ItemTemplate>
  </asp:ListView>

Here is the css

.myitem  
    {  
       background-color:Red;    
    }   
user35
  • 468
  • 1
  • 9
  • 24

1 Answers1

2

Table rows (tr) can't be styled as other elements (e.g. table cells (td)), meaning they don't react on every kind of styling. Why don't you just write:

Fiddle

<asp:ListView ID="msg_list" runat="server">
    <ItemTemplate>
        <table>
            <tr class="myitem">
                <td>
                    <asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' />
                </td>
            </tr>
        </table>
        <%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%></ItemTemplate>
</asp:ListView>



tr.myitem td{
    width:200px;
    height:20px;
    border:2px solid;
    background:red;
}

OR

Fiddle

<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
    <table>
        <tr class="myitem">
            <td>
                <asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' />
            </td>
        </tr>
    </table>
    <%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%></ItemTemplate>

.myitem {
    background:red;
}

EDIT

You need to add <table> tag

Richa
  • 3,261
  • 2
  • 27
  • 51