#1
  1. No Profile Picture
    saved by grace
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    kansas
    Posts
    85
    Rep Power
    13

    Question VB: CSS Styles on ddl listitems


    I am looking for a way to implement CSS styles on DropDownList ListItems. In HTML it's pretty easy:

    PHP Code:
    <select>
    <
    option class="red" value"Yes">Option 1</option>
    <
    option class="pink" value"No">Option 2</option
    </
    select
    But in ASP.NET-VB I'm hitting a snag.

    PHP Code:
    <asp:dropdownlist id="ddlList" runat="server" Width="180px">
    <
    asp:ListItem Value="Yes" class="red">Option1</asp:ListItem>
    <
    asp:ListItem Value="No" class="pink">Option2</asp:ListItem></asp:dropdownlist
    That code doesn't work. When compiled, it totally deletes the "class" attribute.

    Any thoughts?
    I am the way, the truth, and the life: no man cometh unto the Father, but by me.

    John 14:6
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Dublin, Ireland
    Posts
    100
    Rep Power
    12
    hi timandkitty,

    i'm only getting to grips with this .net lark myself and formatting has already caused many headaches!

    but i have come across this. there is a known bug with the dropdownlist web control which prevents you froma dding attributes to it http://support.microsoft.com/default...;en-us;Q309338 - very handy! but then this is microsoft

    they suggest you use a html control instead - i.e. just add the runat="server" to your bog standard select tag - will this let you do what you want? you can still dynamically load this list from a database etc and set the styles at runtime too...
  4. #3
  5. No Profile Picture
    saved by grace
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    kansas
    Posts
    85
    Rep Power
    13

    Talking muchas gracias


    I don't believe that isea will work for me, as I need them to maintain state through postbacks (which they won't, right?) but thanks for the information. At least I can resign myself to dysfunctionality of style for the time-being.
    I am the way, the truth, and the life: no man cometh unto the Father, but by me.

    John 14:6
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Dublin, Ireland
    Posts
    100
    Rep Power
    12
    well like i say i'm new to this stuff... but on doing a quick test the select seemed to remember everything about itself post after post for me??
  8. #5
  9. No Profile Picture
    saved by grace
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    kansas
    Posts
    85
    Rep Power
    13

    cool


    I'll try it out. Thanks mucho, Leprechan Amigo.
    I am the way, the truth, and the life: no man cometh unto the Father, but by me.

    John 14:6

IMN logo majestic logo threadwatch logo seochat tools logo