How define an left atribute on a DropDownList dynamically created

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guilherme21922
    New Member
    • Jan 2008
    • 28

    How define an left atribute on a DropDownList dynamically created

    This is my code:

    DropDownList drop = new DropDownList();
    drop.Style = "left:10px; "; -------------->doesn´t work(error compilation)
    drop.ID = "1";
    drop.Height = 10;
    drop.Width = 130;
    drop.Style("Lef t") = "12";--------------->doesn´t work(error compilation)

    drop.AutoPostBa ck = true;
    drop.Items.Add( "test");
    divDrop.Control s.Add(drop);

    The first error said that "drop.Style " is a CssStyleColecti on.
    The second error said said that "drop.Style " is property not a method.(this sound very wrong to me...i tried because i saw that in a forum)

    Anyone has ideas?

    Thanks
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Code:
    drop.Style.Add("Left", "10px");
    Style is a collection of key value pairs. The key and value are both of type string. Imagine each of the style types from your standard CSS is the key and the items you would provide for that style type would be the value. So to attribute a bunch of fonts (for instance) would be:
    Code:
    drop.Style.Add("font-family", "Arial, Helvetica, Verdana");
    For every style you wish to add, just add it to the list:
    Code:
    drop.Style.Add("font-family", "Arial, Helvetica, Verdana");
    drop.Style.Add("font-size", "10pt");
    drop.Style.Add("color", "red");
    etc etc...

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      MSDN is your friend. Had you bothered to examine the object you were working with, you would have known that it works like a collection.

      Comment

      Working...