drpDownList.DataTextField = "code"
drpDownList.DataValueField = "code"
drpDownList.DataBind()
drpDownList.BackColor = backcolor
drpDownList.Font.Bold = True
drpDownList.Font.Size = fontsize
For k = 0 To drpDownList.Items.Count - 1
drpDownList.Items(k).Text = Trim(drpDownList.Items(k).Text)
If drpDownList.Items(k).Text = "v" Then
drpDownList.Items(k).Attributes.Add("style", "Color: ""#0000FF""")
End If
Next
plhControls.Controls.Add(drpDownList)I think you are going to have to create your own custom control to do that, one that overrides the rendering of the <option> tag. I see what your problem is, the listitem won't render the style property.
btw, much easier to iterate through the items using a for each loop
dim li as listitem
for each li in drpDownList.Items
li.attributes.add("style", "color: blah")
next
I have never done that before. Any info on creating a custom control that would do this?
This may help you get started.
http://www.ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_14/index2.html?page=2
Basically what you will need to do is create a custom control that inherits from listitem, override the render method (which this article goes into detail), and write out the beginning tag how you want it, then call listitems render methods to do the rest.
Yeah it's a mess, but should work, I'm still wondering why you can't just do this with the attributes collection on the listitem. Perhaps there still is a way and I just don't know, probably so :)
Hope this helps,
--Michael
0 comments:
Post a Comment