title: ASP.NET DataList - Row Background Color Change When MouseOver
body: <p>I am trying to make the row background color change when moseover, but I could not make it work. I am not sure I use <code>OnItemDataBound</code> is correct or my codebehind is incorrect.</p>
  
  <p>Please help. Thanks!</p>
  
  <pre><code>&lt;asp:DataList BackColor="#ffffff" id="DataList1" DataSourceID="dsCompanyListPartialMatch"  runat="server" Width="80%" DataKeyField="Company1Word"
      UseAccessibleHeader="true"
      CssClass="books"
      HeaderStyle-CssClass="header"
      ItemStyle-CssClass="item"
      AlternatingItemStyle-CssClass="alternating" 
      GridLines="Both"
      CellPadding="0"
      CellSpacing="0" BorderColor="Black"
      ItemStyle-BorderColor="Black" BorderWidth="0"
       HorizontalAlign="Center"
      RepeatDirection="Vertical" 
      OnItemDataBound="DataList1_ItemDataBound"
      &gt;                
      &lt;HeaderTemplate&gt;
      &lt;/HeaderTemplate&gt;
  
      &lt;ItemStyle BorderColor="black" Font-Size="Medium" /&gt; 
      &lt;ItemTemplate&gt;
          &lt;table border="0"&gt;
          &lt;tr&gt;
              &lt;td style="width: 50px; border-right:1px solid black; border-spacing:0;  text-align:center; "&gt;        
              &lt;asp:LinkButton&gt;
                  &lt;asp:LinkButton ID="LinkButton2" runat="server" Text="+" CommandArgument='&lt;%#Container.ItemIndex%&gt;'
                  OnCommand="LinkButton1_Command"  
                  Font-Underline="false"       
                  Height="25"      
                  Font-Bold="true"                  
                  &gt;&lt;/asp:LinkButton&gt;
              &lt;/td&gt;
                &lt;td style="width: 50px; border-right:1px solid black; border-spacing:0;"&gt;&lt;%#Eval("Row")%&gt;&lt;/td&gt;
                &lt;td style="width: 800px"&gt;&lt;asp:Literal ID="litFoo" runat="server" Text='&lt;%#Eval("Company")%&gt;' /&gt; &lt;/td&gt;
               &lt;td style="width: 600px; text-align:right;"&gt;
                  &lt;asp:CheckBox  id="check1" runat="server" /&gt;
              &lt;/td&gt;
              &lt;asp:Label ID="lblRow" Visible="False" runat="Server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "Row") %&gt;' /&gt;
          &lt;/tr&gt;    
          &lt;/table&gt;     
  
                &lt;asp:Panel ID="pnlChildView" runat="server" style="padding-left:200px;"&gt;
                  &lt;asp:DataList ID="childList" runat="server" Width="100%"&gt;
                     &lt;ItemTemplate&gt;
                          &lt;table class="table1" border="1"&gt;
                         &lt;tr&gt;
                            &lt;td style="width: 800px; border-right:0px solid black; border-spacing:0;"&gt;&amp;#8226; &lt;%#Eval("CompanyName")%&gt;&lt;/td&gt;
                             &lt;td style="text-align:right; "&gt;&lt;a href="/Apps/ERP/Other/CompanyInfo.asp?CompanyID=&lt;%#Eval("CompanyID")%&gt;" &gt;&lt;%#Eval("CompanyID")%&gt;&lt;/a&gt;&lt;/td&gt;                      
                         &lt;/tr&gt;
                          &lt;/table&gt;
                     &lt;/ItemTemplate&gt;
                 &lt;/asp:DataList&gt;
             &lt;/asp:Panel&gt;
      &lt;/ItemTemplate&gt;
       &lt;FooterTemplate&gt;
      &lt;/FooterTemplate&gt;                
  &lt;/asp:DataList&gt;
  </code></pre>
  
  <p>Code behind</p>
  
  <pre><code>protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.Item)
      {
  
          e.Item.Attributes.Add("onmouseover", "this.className='BGMouseOver'");
  
          e.Item.Attributes.Add("onmouseout", "this.className='BGMouseOut'");
  
      }
  }
  </code></pre>