Color not displaying in dropdown list

T

tshad

I am trying to add a different color to some of the rows in my dropdown list
and this is how it is suggested to do this in a couple of articles.

I have a DropDownList call PayDates and I was going to set any row not in my
DataSet to Red.

PayDates.Items[3].Attributes.Add("style", "color:red");

for(ktr=1;ktr<= PayDates.Items.Count - 1;ktr++)//
{
rows = BatchIDDataSet.Tables[0].Select("BatchID = '" +
PayDates.Items[ktr].Text.Substring(0,PayDates.Items[ktr].Text.IndexOf(" /"))
+ "'");
if (rows.Length > 0)
PayDates.Items[ktr].Attributes.Add("style", "color:red");
}

In this case all the rows, except the 1st one should be Red. The debug
showed the rows.length to be 1 for all these rows. But the color was still
black and the viewsource showed that there was no Style attribute anywhere.

So when this didn't work, I tried to add a specific row and not do the
For/Loop:

PayDates.Items[3].Attributes.Add("style", "color:red");

So that only row one would be red. This didn't work either.

What am I missing? The data is there - just all black.

Thanks,
 
T

tshad

Juan T. Llibre said:
If what you want is like : http://asp.net.do/test/dropdowncolor.aspx

...all you need to do is add :

<option style="color: blue;">One</option>
to your options.

That is what:

PayDates.Items[3].Attributes.Add("style", "color:red");

is supposed to do according to these links:

http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp

The dropdown list is:

<asp:dropdownlist id="PayDates" runat="server"></asp:dropdownlist>

The displayed web page is:

<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-08-2006">2006117 / 09-08-2006 / 09-08-06
Bi-weekly</option>
<option value="08-25-2006">V089669 / 08-25-2006 / Reverse Voucher Number
089502</option>
<option value="08-25-2006">2006113 / 08-25-2006 / 08-25-06
Bi-weekly</option>
<option value="08-18-2006">2006116 / 08-18-2006 / Supp H.ortiz/final
Chk</option>
....

As you can see there is no style attribute. The ".Attributes.Add" code is
done at the end of the Sub after the DataBind.

Thanks,

Tom
Here's a handy list of HTML color names :
http://www.w3schools.com/html/html_colornames.asp




tshad said:
I am trying to add a different color to some of the rows in my dropdown
list and this is how it is suggested to do this in a couple of articles.

I have a DropDownList call PayDates and I was going to set any row not in
my DataSet to Red.

PayDates.Items[3].Attributes.Add("style", "color:red");

for(ktr=1;ktr<= PayDates.Items.Count - 1;ktr++)//
{
rows = BatchIDDataSet.Tables[0].Select("BatchID = '" +
PayDates.Items[ktr].Text.Substring(0,PayDates.Items[ktr].Text.IndexOf("
/")) + "'");
if (rows.Length > 0)
PayDates.Items[ktr].Attributes.Add("style", "color:red");
}

In this case all the rows, except the 1st one should be Red. The debug
showed the rows.length to be 1 for all these rows. But the color was
still black and the viewsource showed that there was no Style attribute
anywhere.

So when this didn't work, I tried to add a specific row and not do the
For/Loop:

PayDates.Items[3].Attributes.Add("style", "color:red");

So that only row one would be red. This didn't work either.

What am I missing? The data is there - just all black.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top