Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can set background colors from the .aspx page by specifying either the CssClass, or the BackColor property.. it looks like:</p> <pre><code>&lt;asp:ListBox CssClass="MyListBox" BackColor="#e0e0e0"&gt;&lt;/asp:ListBox&gt; </code></pre> <p>Setting the selected item is a little trickier... I don't believe there is an attribute for this directly. You can set it in javascript, or jQuery, something like:</p> <pre><code>// Never mind, this won't work &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#MyListBox').click(function() { $("#MyListBox option:selected").css("background-color", "#e0e0e0"); }); }); &lt;/script&gt; </code></pre> <p>I'll test that to make sure it works... if you need a straight javascript solution, I'll see what I can come up with. But if you're not using jQuery, and you want fine-grained control over your controls, now is a good time to learn it : )</p> <p>Thanks to Justin for corrections to the script!</p> <p><br /> <strong>EDIT</strong><br /> Hover is easy... add a style:</p> <pre><code> select &gt; option:hover { background-color: #ffffd0; } </code></pre> <p>That will set the background color on any listbox item you hover over on the page. jQuery can be used to set the click function on all listboxes, not just specifically #MyListBox... give me a couple of minutes, I'll add some code</p> <p><br /> <strong>UPDATE</strong><br/> After extensive research, exhausting every resource I had or can put my hands on, the best answer I come up with is: Setting the selected color can't be done.</p> <p>Not even the jQuery code I came up with will work. The selected color is set by the OS, and can't be overridden. </p> <p>Sorry, best I can do is the :hover pseudo-selector<br /> : (</p> <p>.</p>
 

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