Different colors in a DropDownList

T

tshad

Is there a way to set one item in a dropdown list to a different color?

I have a case where I might have 15 items and one is a default and would
like to set the default as green where all the rest are black.

I looked at the examples from
http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp and
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp but I can't
seem to get it to work.

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:

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,

Tom
 
T

tshad

I also tried to add the line to the Pre-Render code:

void Page_PreRender(Object o,EventArgs e)
{
Trace.Warn("In Page_PreRender");
PayDates.Items[3].Attributes.Add("style", "color:red");
}

It gets there and I can see it with the breakpoint as well as in the trace
list.

But here is the view source from the page (you'll notice the style isn't
there)

**********************************************************
<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-15-2006">2006121 / 09-15-2006 / Sup K.mcland/fnl
Chk</option>
<option value="09-11-2006">2006119 / 09-11-2006 / Supp A.heez</option>
<option value="01-13-2006">V091365 / 01-13-2006 / Reverse Voucher Number
01656</option>
<option value="03-24-2006">V091366 / 03-24-2006 / Reverse Voucher Number
01976</option>
<option value="06-22-2006">200691 / 06-22-2006 / A.spyris - Fnl Ck</option>
<option value="06-22-2006">200692 / 06-22-2006 / A.spyris/al Pay</option>
</select>
***********************************************************

Thanks,

Tom
 
G

Guest

Here is your answer

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

Hope it helps :)
--
Programmer


tshad said:
I also tried to add the line to the Pre-Render code:

void Page_PreRender(Object o,EventArgs e)
{
Trace.Warn("In Page_PreRender");
PayDates.Items[3].Attributes.Add("style", "color:red");
}

It gets there and I can see it with the breakpoint as well as in the trace
list.

But here is the view source from the page (you'll notice the style isn't
there)

**********************************************************
<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-15-2006">2006121 / 09-15-2006 / Sup K.mcland/fnl
Chk</option>
<option value="09-11-2006">2006119 / 09-11-2006 / Supp A.heez</option>
<option value="01-13-2006">V091365 / 01-13-2006 / Reverse Voucher Number
01656</option>
<option value="03-24-2006">V091366 / 03-24-2006 / Reverse Voucher Number
01976</option>
<option value="06-22-2006">200691 / 06-22-2006 / A.spyris - Fnl Ck</option>
<option value="06-22-2006">200692 / 06-22-2006 / A.spyris/al Pay</option>
</select>
***********************************************************

Thanks,

Tom

tshad said:
Is there a way to set one item in a dropdown list to a different color?

I have a case where I might have 15 items and one is a default and would
like to set the default as green where all the rest are black.

I looked at the examples from
http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp and
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp but I
can't seem to get it to work.

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:

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,

Tom
 
T

tshad

Sergey Zuyev said:

That was it.

That was one of the articles I looked at but missed the part about the bug
and change the asp:DropDownList to Select. After I did that it works fine.

Thanks,

Tom
Hope it helps :)
--
Programmer


tshad said:
I also tried to add the line to the Pre-Render code:

void Page_PreRender(Object o,EventArgs e)
{
Trace.Warn("In Page_PreRender");
PayDates.Items[3].Attributes.Add("style", "color:red");
}

It gets there and I can see it with the breakpoint as well as in the
trace
list.

But here is the view source from the page (you'll notice the style isn't
there)

**********************************************************
<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-15-2006">2006121 / 09-15-2006 / Sup K.mcland/fnl
Chk</option>
<option value="09-11-2006">2006119 / 09-11-2006 / Supp A.heez</option>
<option value="01-13-2006">V091365 / 01-13-2006 / Reverse Voucher Number
01656</option>
<option value="03-24-2006">V091366 / 03-24-2006 / Reverse Voucher Number
01976</option>
<option value="06-22-2006">200691 / 06-22-2006 / A.spyris - Fnl
Ck</option>
<option value="06-22-2006">200692 / 06-22-2006 / A.spyris/al
Pay</option>
</select>
***********************************************************

Thanks,

Tom

tshad said:
Is there a way to set one item in a dropdown list to a different color?

I have a case where I might have 15 items and one is a default and
would
like to set the default as green where all the rest are black.

I looked at the examples from
http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp and
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp but I
can't seem to get it to work.

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:

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,

Tom
 
T

tshad

BTW, I can't seem to get the text field of the Select tag:

<SELECT id="PayDates" name="PayDates" runat="server"></SELECT>

To get the Value it would be:

PayDates.Value

If it was an asp:dropdownlist - it would be:

PayDates.SelectedItem.Text

How do I get it in this case?

Thanks,

Tom

tshad said:
Sergey Zuyev said:

That was it.

That was one of the articles I looked at but missed the part about the bug
and change the asp:DropDownList to Select. After I did that it works
fine.

Thanks,

Tom
Hope it helps :)
--
Programmer


tshad said:
I also tried to add the line to the Pre-Render code:

void Page_PreRender(Object o,EventArgs e)
{
Trace.Warn("In Page_PreRender");
PayDates.Items[3].Attributes.Add("style", "color:red");
}

It gets there and I can see it with the breakpoint as well as in the
trace
list.

But here is the view source from the page (you'll notice the style isn't
there)

**********************************************************
<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-15-2006">2006121 / 09-15-2006 / Sup K.mcland/fnl
Chk</option>
<option value="09-11-2006">2006119 / 09-11-2006 / Supp A.heez</option>
<option value="01-13-2006">V091365 / 01-13-2006 / Reverse Voucher
Number
01656</option>
<option value="03-24-2006">V091366 / 03-24-2006 / Reverse Voucher
Number
01976</option>
<option value="06-22-2006">200691 / 06-22-2006 / A.spyris - Fnl
Ck</option>
<option value="06-22-2006">200692 / 06-22-2006 / A.spyris/al
Pay</option>
</select>
***********************************************************

Thanks,

Tom

Is there a way to set one item in a dropdown list to a different
color?

I have a case where I might have 15 items and one is a default and
would
like to set the default as green where all the rest are black.

I looked at the examples from
http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp and
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp but I
can't seem to get it to work.

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:

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,

Tom
 
T

tshad

Figured it out:

PayDates.Items[ktr].Text

Tom
tshad said:
BTW, I can't seem to get the text field of the Select tag:

<SELECT id="PayDates" name="PayDates" runat="server"></SELECT>

To get the Value it would be:

PayDates.Value

If it was an asp:dropdownlist - it would be:

PayDates.SelectedItem.Text

How do I get it in this case?

Thanks,

Tom

tshad said:
Sergey Zuyev said:

That was it.

That was one of the articles I looked at but missed the part about the
bug and change the asp:DropDownList to Select. After I did that it works
fine.

Thanks,

Tom
Hope it helps :)
--
Programmer


:

I also tried to add the line to the Pre-Render code:

void Page_PreRender(Object o,EventArgs e)
{
Trace.Warn("In Page_PreRender");
PayDates.Items[3].Attributes.Add("style", "color:red");
}

It gets there and I can see it with the breakpoint as well as in the
trace
list.

But here is the view source from the page (you'll notice the style
isn't
there)

**********************************************************
<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-15-2006">2006121 / 09-15-2006 / Sup K.mcland/fnl
Chk</option>
<option value="09-11-2006">2006119 / 09-11-2006 / Supp A.heez</option>
<option value="01-13-2006">V091365 / 01-13-2006 / Reverse Voucher
Number
01656</option>
<option value="03-24-2006">V091366 / 03-24-2006 / Reverse Voucher
Number
01976</option>
<option value="06-22-2006">200691 / 06-22-2006 / A.spyris - Fnl
Ck</option>
<option value="06-22-2006">200692 / 06-22-2006 / A.spyris/al
Pay</option>
</select>
***********************************************************

Thanks,

Tom

Is there a way to set one item in a dropdown list to a different
color?

I have a case where I might have 15 items and one is a default and
would
like to set the default as green where all the rest are black.

I looked at the examples from
http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp and
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp but I
can't seem to get it to work.

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:

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,

Tom
 
T

tshad

What I don't understand is why a postback would lose the attributes I set:

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

Where the object is defined in my file as:

<SELECT id="PayDates" name="PayDates" runat="server"></SELECT>

When I come back to my page by a postback, the colors are gone.

How do I fix that?

Thanks,

Tom
tshad said:
BTW, I can't seem to get the text field of the Select tag:

<SELECT id="PayDates" name="PayDates" runat="server"></SELECT>

To get the Value it would be:

PayDates.Value

If it was an asp:dropdownlist - it would be:

PayDates.SelectedItem.Text

How do I get it in this case?

Thanks,

Tom

tshad said:
Sergey Zuyev said:

That was it.

That was one of the articles I looked at but missed the part about the
bug and change the asp:DropDownList to Select. After I did that it works
fine.

Thanks,

Tom
Hope it helps :)
--
Programmer


:

I also tried to add the line to the Pre-Render code:

void Page_PreRender(Object o,EventArgs e)
{
Trace.Warn("In Page_PreRender");
PayDates.Items[3].Attributes.Add("style", "color:red");
}

It gets there and I can see it with the breakpoint as well as in the
trace
list.

But here is the view source from the page (you'll notice the style
isn't
there)

**********************************************************
<select name="PayDates" id="PayDates">
<option value="Select Date">Select Date</option>
<option value="09-15-2006">2006121 / 09-15-2006 / Sup K.mcland/fnl
Chk</option>
<option value="09-11-2006">2006119 / 09-11-2006 / Supp A.heez</option>
<option value="01-13-2006">V091365 / 01-13-2006 / Reverse Voucher
Number
01656</option>
<option value="03-24-2006">V091366 / 03-24-2006 / Reverse Voucher
Number
01976</option>
<option value="06-22-2006">200691 / 06-22-2006 / A.spyris - Fnl
Ck</option>
<option value="06-22-2006">200692 / 06-22-2006 / A.spyris/al
Pay</option>
</select>
***********************************************************

Thanks,

Tom

Is there a way to set one item in a dropdown list to a different
color?

I have a case where I might have 15 items and one is a default and
would
like to set the default as green where all the rest are black.

I looked at the examples from
http://www.c-sharpcorner.com/Code/2003/July/ColorFullDropDown.asp and
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp but I
can't seem to get it to work.

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:

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,

Tom
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top