Cluj München 1140km

Gânduri clujene din Bavaria

München - Munich - Monaco di Baviera

26. martie 2009 17:13
by skorpionking
0 Comentarii

.NET 60 seconds code: changing the border of a DropDownList in ASP.NET

26. martie 2009 17:13 by skorpionking | 0 Comentarii

So gents and lads, have you ever wondered how to change for example the border style of a DropDownList in ASP.NET which will be rendered in HTML as a Select element?

You can't change the border style in ASP.NET of a DropDownList control, but you can do it with a trick: wrap your DropDownList in a Div element such that the Div wraps perfectely it. Than you can change the Div's border which will have as an effect simulating the change of DropDownList's border.

For example you have in ASPX the following markup:

  <div id="div" runat="server" class="divnormal">
        <asp:DropDownList ID="ddl" runat="server" CssClass="dropdown" AutoPostBack="true"
              OnSelectedIndexChanged="ddl_OnSelectedIndexChanged"></asp:DropDownList>
  </div>

 and the styles:

.divnormal
{
 width:auto;
 border:1px solid #999999;
}

.divred
{
 width:auto;
 border:2px solid Red;
}

the in OnPrender or SelectedIndexChanged or other event, put the following code:

div.Attributes["class"] = "divred";

Voila! The DropDownList will have a red border. Actually the Div surrounding it ;-)  Life is good, happy coding! :-)

 

Adaugă comentariu

biuquote
Loading