Thursday, March 22, 2012

setting the font color to red for Dropdownlist control list it

Thanks to everyone for your reply.
I know that this is a bug but wasn't sure if Microsoft fixed the bug or not.
****************************************
************
"Juan T. Llibre" wrote:

> Something as simple as :
> <option style="color: red;">Something</option>
> ...works.
> Also, you can use a Listbox instead of a DropdownList if you want to do it
programmatically.
> They have roughly the same functionality, anyway.
> myconnection = New SqlConnection("Server=YourServer;Integrated Security=Tr
ue;Database=Northwind")
> myda = New SqlDataAdapter("Select * from Products ", myconnection)
> ds = New DataSet()
> myda.Fill(ds, "AllTables")
> dim i as Integer
> For i = 0 To ds.Tables(0).Rows.Count - 1
> list1.Items.Add(New ListItem(ds.Tables(0).Rows(i)("UnitPrice"),
> ds.Tables(0).Rows(i)("ProductID")))
> If ds.Tables(0).Rows(i)("UnitPrice") <= 40 Then
> list1.Items(i).Attributes.Add("style", "color:red")
> Else
> list1.Items(i).Attributes.Add("style", "color:green")
> End If
> Next
> See it running at : http://asp.net.do/test/dropdowncolor2.aspx
> Use anything you'd like for your conditions...
>
>
> Juan T. Llibre, asp.net MVP
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en espa?ol : http://asp.net.do/foros/
> ===================================
> "Alexey Smirnov" <alexey.smirnov@dotnet.itags.org.gmail.com> wrote in message
> news:1174339905.643056.214630@dotnet.itags.org.y66g2000hsf.googlegroups.com...
>
>re:
> I know that this is a bug but wasn't sure if Microsoft fixed the bug or not.[/colo
r]
*WAS* a bug ! :-)
In the previous example, I used a <SELECT directly:
<select name="DDL1" id="DDL1" size="10">
...but ASP.NET renders a dropdownlist control as a select, so there's
no problem getting a dropdownlist to render its contents in different colors
.
I modified the example so it uses an ASP.NET dropdownlist control:
http://asp.net.do/test/dropdowncolor3.aspx
DDL1.Items.Add(New ListItem(ds.Tables(0).Rows(i)("UnitPrice"), ds.Tables(0).
Rows(i)("ProductID")))
If ds.Tables(0).Rows(i)("UnitPrice") <= 40 Then
DDL1.Items(i).Attributes.Add("style", "color:red")
Else
DDL1.Items(i).Attributes.Add("style", "color:green")
End If
Next
That, and changing the <SELECT to :
<asp:DropDownList id="DDL1" size="10" runat="server" />
...produces the exact same HTML as the previous example.
View the source for
http://asp.net.do/test/dropdowncolor2.aspx
and
http://asp.net.do/test/dropdowncolor3.aspx
to verify that.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Rekha" <Rekha@.discussions.microsoft.com> wrote in message
news:EB6AF2B3-8FE5-44E7-A127-5826625D4C13@.microsoft.com...
> Thanks to everyone for your reply.
> I know that this is a bug but wasn't sure if Microsoft fixed the bug or no
t.
> ****************************************
************
> "Juan T. Llibre" wrote:
>
Lines: 128
Thread-Topic: setting the font color to red for Dropdownlist control list it
thread-index: AcdrJF1tG6gu3rwYRpis08gB0fFE6A==
X-WBNR-Posting-Host: 135.245.8.36
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 8bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2757
NNTP-Posting-Host: tk2msftsbfm01.phx.gbl 10.40.244.148
Xref: leafnode.mcse.ms microsoft.public.dotnet.framework.aspnet:48579
Juan,
Thanks for your reply.
The issue that I have is I am updating the list box items color based on the
selection made in a calendar field. When the user selects a date in the
calendar field, the list box items are color coded. I am updating the listbo
x
items in the Calendar_SelectionChanged event but I don't see the color
changing.
Any ideas!!
Thanks!
"Juan T. Llibre" wrote:

> re:
> *WAS* a bug ! :-)
> In the previous example, I used a <SELECT directly:
> <select name="DDL1" id="DDL1" size="10">
> ...but ASP.NET renders a dropdownlist control as a select, so there's
> no problem getting a dropdownlist to render its contents in different colo
rs.
> I modified the example so it uses an ASP.NET dropdownlist control:
> http://asp.net.do/test/dropdowncolor3.aspx
> DDL1.Items.Add(New ListItem(ds.Tables(0).Rows(i)("UnitPrice"), ds.Tables
(0).Rows(i)("ProductID")))
> If ds.Tables(0).Rows(i)("UnitPrice") <= 40 Then
> DDL1.Items(i).Attributes.Add("style", "color:red")
> Else
> DDL1.Items(i).Attributes.Add("style", "color:green")
> End If
> Next
> That, and changing the <SELECT to :
> <asp:DropDownList id="DDL1" size="10" runat="server" />
> ...produces the exact same HTML as the previous example.
> View the source for
> http://asp.net.do/test/dropdowncolor2.aspx
> and
> http://asp.net.do/test/dropdowncolor3.aspx
> to verify that.
>
>
> Juan T. Llibre, asp.net MVP
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en espa?ol : http://asp.net.do/foros/
> ===================================
> "Rekha" <Rekha@.discussions.microsoft.com> wrote in message
> news:EB6AF2B3-8FE5-44E7-A127-5826625D4C13@.microsoft.com...
>
>

0 comments:

Post a Comment