Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should actually be done during the RowCreatedEvent. Just tested the following code and it worked marvelously to highlight/unhighlight a row on mouseover.</p> <pre><code>Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ccaaaa';") e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff';") End If End Sub </code></pre> <p>EDIT: Appending html output (NOTE: Works in both VB and C# with RowCreated - same output)</p> <pre><code>&lt;div&gt; &lt;table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;"&gt; &lt;tr&gt; &lt;th scope="col"&gt;ST_CD&lt;/th&gt;&lt;th scope="col"&gt;ST_CD_ALPHA&lt;/th&gt;&lt;th scope="col"&gt;ST_DESC&lt;/th&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;04&lt;/td&gt;&lt;td&gt;CA&lt;/td&gt;&lt;td&gt;CALIFORNIA &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;34&lt;/td&gt;&lt;td&gt;OH&lt;/td&gt;&lt;td&gt;OHIO &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;41&lt;/td&gt;&lt;td&gt;TN&lt;/td&gt;&lt;td&gt;TENNESSEE &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;42&lt;/td&gt;&lt;td&gt;TX&lt;/td&gt;&lt;td&gt;TEXAS &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;45&lt;/td&gt;&lt;td&gt;VA&lt;/td&gt;&lt;td&gt;VIRGINIA &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;46&lt;/td&gt;&lt;td&gt;WA&lt;/td&gt;&lt;td&gt;WASHINGTON &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;49&lt;/td&gt;&lt;td&gt;WY&lt;/td&gt;&lt;td&gt;WYOMING &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;14&lt;/td&gt;&lt;td&gt;IA&lt;/td&gt;&lt;td&gt;IOWA &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;24&lt;/td&gt;&lt;td&gt;MO&lt;/td&gt;&lt;td&gt;MISSOURI &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;40&lt;/td&gt;&lt;td&gt;SD&lt;/td&gt;&lt;td&gt;SOUTH DAKOTA &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;43&lt;/td&gt;&lt;td&gt;UT&lt;/td&gt;&lt;td&gt;UTAH &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;44&lt;/td&gt;&lt;td&gt;VT&lt;/td&gt;&lt;td&gt;VERMONT &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;47&lt;/td&gt;&lt;td&gt;WV&lt;/td&gt;&lt;td&gt;WEST VIRGINIA &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;48&lt;/td&gt;&lt;td&gt;WI&lt;/td&gt;&lt;td&gt;WISCONSIN &lt;/td&gt; &lt;/tr&gt;&lt;tr onmouseover="this.style.backgroundColor='#ccaaaa';" onmouseout="this.style.backgroundColor='#ffffff';"&gt; &lt;td&gt;54&lt;/td&gt;&lt;td&gt;AK&lt;/td&gt;&lt;td&gt;ALASKA &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>EDIT: Here is the HTML side that I've got. I kept it simple. It's possible in your HTML side you have a css configuration that is interfering.</p> <pre><code>&lt;div&gt; &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="ST_CD" HeaderText="ST_CD" SortExpression="ST_CD" /&gt; &lt;asp:BoundField DataField="ST_CD_ALPHA" HeaderText="ST_CD_ALPHA" SortExpression="ST_CD_ALPHA" /&gt; &lt;asp:BoundField DataField="ST_DESC" HeaderText="ST_DESC" SortExpression="ST_DESC" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:WebTestConnectionString %&gt;" SelectCommand="SELECT [ST_CD], [ST_CD_ALPHA], [ST_DESC] FROM [STATE_VALUES] WHERE ([ST_CD] LIKE '%' + @ST_CD + '%')"&gt; &lt;SelectParameters&gt; &lt;asp:Parameter DefaultValue="4" Name="ST_CD" Type="String" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload