Load all colors names to dropdownlist using ASP.NET with C# Language

Some of the times we need to create a webpage, where user need to access the color. For this one, we can use System.Drawing.Color namespace. In the below example, i am taking all colors name from the .net framework.
Output:








ASP.NET Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <b>All Colors List from System.Drawing.Color</b>
    <asp:DropDownList ID="ddlColorLoad" runat="server"></asp:DropDownList>
    <br />
    <b>http://aspnettutorialonline.blogspot.com</b>
    </div>
    </form>
</body>
</html>




CSharp Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (System.Reflection.PropertyInfo property in typeof(Color).GetProperties())
        {
            if (property.PropertyType.FullName == "System.Drawing.Color")
                ddlColorLoad.Items.Add(property.Name);
        }
    }
}



Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar