You need to make instances of Html control inside of for loop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder stringBuilder = new StringBuilder(string.Empty);
int num = DropDownList1.Items.Count;
for(int i = 0 ; i< DropDownList1.Items.Count ; i++)
{
System.Web.UI.HtmlControls.HtmlGenericControl NewDiv = newSystem.Web.UI.HtmlControls.HtmlGenericControl();
NewDiv.ID = "Newdiv" + i + " ";
NewDiv.Style["height"] = "15px";
NewDiv.Style["width"] = "15px";
NewDiv.Style["margin"] = "2px";
NewDiv.Style["display"] = "block";
NewDiv.Style["Background-color"] = Convert.ToString(DropDownList1.Items[i].Value);
divcolor.Controls.Add(NewDiv);
}
}
}
</style>