Ask a Question related to ASP.NET General, Design and Development.
-
Gandalf #1
Different styles in DropDownList items?
I wish to apply different styles to items in a DropDownList. However, any
styles applied in the codebehind (using the ListItem.Addtributes property)
do not get rendered. This is an old question but I've yet to see a
satisfactory answer, other than it's a bug in the DropDownList. It seems to
work for a HtmlSelect control, but this does not provide the AutoPostBack
feature I require. Any help appreciated.
--
Gandalf Guest
-
#24095 [Com]: phpinfo styles override page styles and damage appearance
ID: 24095 Comment by: joe at monkeydepartment dot com Reported By: generic at thetahat dot com Status: Open... -
Creating master page where global items arearranged ABOVE local items
When you create a mater page, obviously all the items are arranged below anything on the individual pages. Is there a way of creating a master... -
possible for publishers to edit Library Items / recurrent items like navigation?
No, you have to use an include of some sort. If you don't want to use SSI you can do it with Javascript. Search Google with the keyword "Javascript... -
changing type size in paragraph styles and how it effects nested styles
In a book I'm developing, I decided to up the point size for my "first paragraph" and "body text" in my paragraph styles. I have nested styles in... -
HELP! DropDownList Items property in composite control -- collection editor support question!
Hi, I have a composite web custom control consisting of a textbox, a button, and a dropdownlist.. I'm trying to expose the Items property from... -
Ken Cox [Microsoft MVP] #2
Re: Different styles in DropDownList items?
You pretty well have to do it in client-side script. Of course you can use the
codebehind to output the client-side script like this:
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim sb As New System.Text.StringBuilder
If Not IsPostBack Then
lstArtTipo.Items.Add("First item")
lstArtTipo.Items.Add("Second item")
lstArtTipo.Items.Add("Third item")
lstArtTipo.Items.Add("Fourth item")
End If
sb.Append("<script language='javascript'>")
sb.Append("function docolorddl(selI)")
sb.Append("{document.Form1.lstArtTipo.options")
sb.Append("[selI].style.backgroundColor=")
sb.Append("'PowderBlue';}</script>")
Page.RegisterClientScriptBlock("bgcolor", sb.ToString)
sb.Length = 0
sb.Append("<script language='javascript'>")
sb.Append("docolorddl(document.Form1.lstArtTipo.se lectedIndex);")
sb.Append("</script>")
Page.RegisterStartupScript("bgstart", sb.ToString)
lstArtTipo.Attributes.Add("onchange", _
"docolorddl(this.selectedIndex);")
End Sub
"Gandalf" <gandalf@sauron.com> wrote in message
news:OIZvNUcRDHA.3192@TK2MSFTNGP10.phx.gbl...
I wish to apply different styles to items in a DropDownList. However, any
styles applied in the codebehind (using the ListItem.Addtributes property)
do not get rendered. This is an old question but I've yet to see a
satisfactory answer, other than it's a bug in the DropDownList. It seems to
work for a HtmlSelect control, but this does not provide the AutoPostBack
feature I require. Any help appreciated.
--
Ken Cox [Microsoft MVP] Guest
-
Teemu Keiski #3
Re: Different styles in DropDownList items?
I answered same kind of question on ASP.NET Forums, but on that occasion I
instructed the user in developing custom control to overcome the problem.
[url]http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=253555[/url]
--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
[url]http://www.mansoft.fi[/url]
ASP.NET Forums Moderator, [url]www.asp.net[/url]
AspAlliance Columnist, [url]www.aspalliance.com[/url]
Email:
[email]joteke@aspalliance.com[/email]
"Gandalf" <gandalf@sauron.com> kirjoitti viestissä
news:OIZvNUcRDHA.3192@TK2MSFTNGP10.phx.gbl...to> I wish to apply different styles to items in a DropDownList. However, any
> styles applied in the codebehind (using the ListItem.Addtributes property)
> do not get rendered. This is an old question but I've yet to see a
> satisfactory answer, other than it's a bug in the DropDownList. It seems> work for a HtmlSelect control, but this does not provide the AutoPostBack
> feature I require. Any help appreciated.
> --
>
>
>
Teemu Keiski Guest
-
Gandalf #4
Re: Different styles in DropDownList items?
Thanks Ken. WHat you are doing is setting the color of the selected item to
powderblue, whereas I want each item in the dropdown to be a different
color. I'm sure I could do it writing reams of jscript but i'd rather not.
;-)
--
"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@sympatico.ca> wrote in message
news:uY7jgpcRDHA.2332@TK2MSFTNGP10.phx.gbl...the> You pretty well have to do it in client-side script. Of course you can useto> codebehind to output the client-side script like this:
>
> Private Sub Page_Load _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) _
> Handles MyBase.Load
> Dim sb As New System.Text.StringBuilder
> If Not IsPostBack Then
> lstArtTipo.Items.Add("First item")
> lstArtTipo.Items.Add("Second item")
> lstArtTipo.Items.Add("Third item")
> lstArtTipo.Items.Add("Fourth item")
> End If
> sb.Append("<script language='javascript'>")
> sb.Append("function docolorddl(selI)")
> sb.Append("{document.Form1.lstArtTipo.options")
> sb.Append("[selI].style.backgroundColor=")
> sb.Append("'PowderBlue';}</script>")
> Page.RegisterClientScriptBlock("bgcolor", sb.ToString)
> sb.Length = 0
> sb.Append("<script language='javascript'>")
> sb.Append("docolorddl(document.Form1.lstArtTipo.se lectedIndex);")
> sb.Append("</script>")
> Page.RegisterStartupScript("bgstart", sb.ToString)
> lstArtTipo.Attributes.Add("onchange", _
> "docolorddl(this.selectedIndex);")
> End Sub
>
> "Gandalf" <gandalf@sauron.com> wrote in message
> news:OIZvNUcRDHA.3192@TK2MSFTNGP10.phx.gbl...
> I wish to apply different styles to items in a DropDownList. However, any
> styles applied in the codebehind (using the ListItem.Addtributes property)
> do not get rendered. This is an old question but I've yet to see a
> satisfactory answer, other than it's a bug in the DropDownList. It seems> work for a HtmlSelect control, but this does not provide the AutoPostBack
> feature I require. Any help appreciated.
> --
>
>
>
>
Gandalf Guest



Reply With Quote

