title: ASP.NET GridView - Cannot set the colour of the row during databind?
body: <p>This is driving me NUTS!  It's something that I've done 100s of time with a Datagrid.  I'm now using a Gridview and I can't figure this out.  </p>
  
  <p>I've got this grid:</p>
  
  <pre><code>&lt;asp:GridView AutoGenerateColumns="false" runat="server" ID="gvSelect" CssClass="GridViewStyle"
          GridLines="None" ShowHeader="False" PageSize="20" AllowPaging="True"&gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label runat="server" ID="lbldas" Text="blahblah"&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
  </code></pre>
  
  <p>And during the RowDataBound I've tried:</p>
  
  <pre><code>Protected Sub gvSelect_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSelect.RowCreated
      If e.Row.RowType = DataControlRowType.DataRow Then
          e.Row.Attributes.Add("onMouseOver", "this.style.backgroundColor='lightgrey'")
      End If
  End Sub
  </code></pre>
  
  <p>And it NEVER sets the row backcolor.. I've been successful in using:</p>
  
  <pre><code>gridrow.Cells(0).BackColor = Drawing.Color.Blue
  </code></pre>
  
  <p>But doing the entire row? NOPE!  and it's driving me nuts.. does ANYONE have solution for me?</p>
  
  <p>And just for fun I put this on the SAME page:</p>
  
  <pre><code>&lt;asp:DataGrid AutoGenerateColumns="false" runat="server" ID="dgSelect" GridLines="None"
          ShowHeader="False" PageSize="20" AllowPaging="True"&gt;
          &lt;Columns&gt;
              &lt;asp:TemplateColumn&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label runat="server" ID="lbldas" Text="blahblah"&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateColumn&gt;
          &lt;/Columns&gt;
      &lt;/asp:DataGrid&gt;
  </code></pre>
  
  <p>And in the ItemDataBound I put:</p>
  
  <pre><code>If Not e.Item.ItemType = ListItemType.Header And Not e.Item.ItemType = ListItemType.Footer Then
          e.Item.Attributes.Add("onMouseOver", "this.style.backgroundColor='lightgrey'")
  End If
  </code></pre>
  
  <p>And it works as expected..  SO What am I doing wrong with the Gridview?</p>
  
  <p>**UPDATE ************************</p>
  
  <p>I thought I'd post the resulting HTML to show that any styles aren't affecting this. </p>
  
  <p>Here's the gridview html:</p>
  
  <pre><code>&lt;div class="AspNet-GridView" id="gvSelect"&gt; 
  &lt;table cellpadding="0" cellspacing="0" summary=""&gt; 
      &lt;tbody&gt; 
          &lt;tr&gt; 
              &lt;td&gt; 
                  &lt;span id="gvSelect_ctl02_lbldas"&gt;blahblah&lt;/span&gt; 
              &lt;/td&gt; 
          &lt;/tr&gt; 
      &lt;/tbody&gt; 
  &lt;/table&gt; 
   &lt;/div&gt;
  </code></pre>
  
  <p>And here's the resulting Datagrid HTML:</p>
  
  <pre><code>&lt;table cellspacing="0" border="0" id="dgSelect" style="border-collapse:collapse;"&gt; 
  &lt;tr onMouseOver="this.style.backgroundColor='lightgrey'"&gt; 
      &lt;td&gt; 
          &lt;span id="dgSelect_ctl03_lbldas"&gt;blahblah&lt;/span&gt; 
              &lt;/td&gt; 
  &lt;/tr&gt;
   &lt;/table&gt; 
  </code></pre>
  
  <p>See.. the main difference is the  tag.  It never gets set in the gridview.. and I don't know why.. I've traced through it.. and the code gets run..  :S</p>