Today, I have provided an article showing you how to change the color of text using a DropDownList in ASP. NET. There are many ways in which a user can change the color of text using a DropDownList. Here, we use the color class to change the color of text using a DropDownList. It's easy to implement. We drag and drop two DropDownList controls onto the form; one is for the foreground color and the second one is used to change the background color and also drag and drop a Label control for showing the changing color effect. First of all start Visual Studio .NET and make a new ASP.NET web site using Visual Studio 2010.

Now you have to create a web site.

Go to Visual Studio 2010

New-> Select a website application

Click OK

Now add a new page to the website.

Go to the Solution Explorer

Right-click on the Project name

Select add new item

Add new web page and give it a name

Click OK

Now drag and drop two DropDownList controls from the Toolbox to the page; one is for the foreground color and the second one is used to change the background color. Let's take a look at a practical example. The .aspx code will be as shown below.

This is a base class for color values. By adding a reference to the System.Drawing to use the color class. You can use many known colors using the named properties of the Color type.

FromName Method

You may have to convert from a string to a color type. For example, if you accept user input and the user types the word "white", you can convert this into a real color and use it in your program or obtain its ARGB value using the Color.FromName method.

// Create the color from a string.

Color white = Color.FromName("white");

// Color will have appropriate R G B values.

Console.WriteLine(white.R);

Console.WriteLine(white.G);

Console.WriteLine(white.B);

Now double-click on the page and write the following code to change the color of the text using DropDownList.