Home All Groups Group Topic Archive Search About

Color not displaying in dropdown list

Author
7 Sep 2006 4:05 PM
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,

Author
7 Sep 2006 4:43 PM
Juan T. Llibre
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.

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



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Show quoteHide quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:%23Xwqtdp0GHA.1252@TK2MSFTNGP04.phx.gbl...
>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,
>
>
Are all your drivers up to date? click for free checkup

Author
8 Sep 2006 4:48 PM
tshad
"Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
news:uT2Exyp0GHA.4632@TK2MSFTNGP03.phx.gbl...
> 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

Show quoteHide quote
>
> Here's a handy list of HTML color names :
> http://www.w3schools.com/html/html_colornames.asp
>
>
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en español : http://asp.net.do/foros/
> ===================================
> "tshad" <tscheider***@ftsolutions.com> wrote in message
> news:%23Xwqtdp0GHA.1252@TK2MSFTNGP04.phx.gbl...
>>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,
>>
>>
>
>

Bookmark and Share