Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Changing Background color from a Drop Down list

.net dropdown list item

  • Please log in to reply
1 reply to this topic

#1 luffy mcawesome

luffy mcawesome

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 16 September 2012 - 09:48 AM

Write an ASP.NET program using a DropDownList control that automatically changes the background color of a page once any one of the items: Red, Green and Blue, is selected.


  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 16 September 2012 - 06:50 PM

Here is your ASPX HTML code --

<body id="PageBody" runat="server">
<form id="form1" runat="server">
<asp:DropDownList id="ColorList"
AutoPostBack="True"
onselectedIndexChanged="Color_Selection_Change"
runat="server">

<asp:ListItem Selected="True" Value="White">White</asp:ListItem>
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>

</asp:DropDownList>

</form>
</body>

And here is the code behind --
public void Color_Selection_Change(Object sender, EventArgs e)
        {
            PageBody.Attributes["bgColor"] =  System.Drawing.Color.FromName(ColorList.SelectedItem.Value).Name;
        }

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download