Thursday, March 22, 2012

listbox color change

i'm trying to get specific lines to change colors in my listbox--what am I doing wrong, how do I change specific a specific row or item in the listbox?

For x = 0To DsEmpSelection1.Employee.Rows.Count - 1
If DsEmpSelection1.Employee.Rows(x).IsNull(3) =TrueAnd DsEmpSelection1.Employee.Rows(x).IsNull(4) =TrueThen
lbxEmployeeList.ForeColor = Color.Black
Else
lbxEmployeeList.ForeColor = Color.Red
EndIf
Next

AFAIK you don't.
You'll have to build a custom control (or dl one) if you want anything "fancy" in the listbox.


Once again, you are limited not only by theshortcomings of the <select> element, but by the lack ofrendering detail in the asp:Listbox object as well!
If you want this level of granularity in yourstyling, you'll need to (a) use an HtmlSelect object instead or (b)adjust the styles client-side after page load, e.g.
var theOption = document.getElementById("myList").options[2];
theOption.style.color = "red";
theOption.style.background = "black";
HTH...


Curt_C wrote:

AFAIK you don't.
You'll have to build a custom control (or dl one) if you want anything "fancy" in the listbox.


Well, if it's custom controls you want, look no further thanEasyListBox(free unlimited trial too)! However, you can in fact adjustsimple things like colors in an option if you don't mind tinkering abit.
:-D

PeterBrunone wrote:

Once again, you are limited not only by the shortcomings of the <select> element, but by the lack of rendering detail in the asp:Listbox object as well!
If you want this level of granularity in your styling, you'll need to (a) use an HtmlSelect object instead or (b) adjust the styles client-side after page load, e.g.
var theOption = document.getElementById("myList").options[2];
theOption.style.color = "red";
theOption.style.background = "black";
HTH...


What do you mean the shortcomings of the <select> element? i'm not sure of how I can use what you said if I'm using a dataset.

onewisehobbit wrote:


What do youmean the shortcomings of the <select> element? i'm not sure ofhow I can use what you said if I'm using a dataset.


I'm going to assume those two weren't related :)
The select element is how listboxes, dropdowns, and all similarcontrols render as HTML in the browser. Usually when people wantto customize it, they find that they can't. However, in yourcase, the problem isn't the select element, but lack of control youhave over it through the listbox object... so I guess my statementcould have been worded a bit more precisely. My apologies.
Whether you're using a dataset or something else, you can't controlthese attributes directly through the listbox control. You can,however, use an HtmlSelect with Multiple set to true, bind it to yourdataset, and then do your loop like so:

For x = 0To DsEmpSelection1.Employee.Rows.Count - 1
If DsEmpSelection1.Employee.Rows(x).IsNull(3) =TrueAnd DsEmpSelection1.Employee.Rows(x).IsNull(4) =TrueThen
lbxEmployeeList.Items(x).Attributes.Add("style","color:black;")
EndIf
Next

You can just set the listbox's color to red using the style collectionand then only set the style on null (black) items. Let me know ifyou need more.
<edit>
By the way, your HtmlSelect would simply look like this (unless you want to add more attributes):
<select id="lbxEmployeeList" runat="server" style="color:red;">
</select>
</edit>

Do I just wrap the select around my <asp:Listbox> or do I replace <asp:listbox> with select?



You would use it in place of the ListBox control.


Ok well I got it working and about that time --boss came along and wanted it changed to show a pop-message instead -- thanks for all the help. I really appreciate it.
Make sure you put the right cover sheet on your TPS report; they'll ding you for that too.
Was he looking for something likethis? I'm thinking probably not, but if you ever need it, there it is.


They can't stick w/ a design they like--they want a listbox--but no 3rd party control (trust me I'd like to use yours). They want some lines to be Red based on certain criteria. They don't want a select b/c of the appearance, not a box like the listbox. And you can only have one selection. I'm so frustrated!
What do they have against 3rd party controls? They are likely going to pay more for you to work this out than just using a pre-built control...
Yes I'm aware, but unfortunately, I'm at the bottom of the totem pole in the decision making process.
Perhaps, the following may be possible--this was a possibility they said might pass their approval. In the following thread: http://forums.asp.net/1120475/ShowPost.aspx

Well, if they still don't want 3rd party controls, maybethey'd consider spending all that extra development money (that they'llhave to spend) on a listbox specialist :)
I'm not really sure what that checkmark question wasabout, but you can use an image or a character that you flip around...or if you want to get fancy, you can put the checkbox HTML into thequery text (or just in the repeater or whatever you're using) and switch that on and off as necessary...

0 comments:

Post a Comment