Since nobody has tackled the performance aspect of this question, I thought I would give it a go. My initial hypothesis was that either of these two options is going to net you similar performance since they result in nearly identical rendered HTML. However, I put together the following .aspx page to test my theory.
public enum ListType
{
DropDownList,
HtmlList
}
public partial class ListControlRenderTimeComparison : System.Web.UI.Page
{
private Dictionary<ListType, Action<Int32>> _listMap = new Dictionary<ListType, Action<Int32>>();
protected void Page_Load(object sender, EventArgs e)
{
InitializeListMap();
for (int i = 0; i < ControlsToRender; i++)
{
_listMap[ListToRender](NumberOfItems);
}
}
private void InitializeListMap()
{
_listMap.Add(ListType.DropDownList, AddDropDownList);
_listMap.Add(ListType.HtmlList, AddHtmlList);
}
private void AddDropDownList(Int32 controlsToAdd)
{
var ddl = new DropDownList();
for (int i = 0; i < controlsToAdd; i++)
ddl.Items.Add((i + 1).ToString());
form1.Controls.Add(ddl);
}
private void AddHtmlList(Int32 controlsToAdd)
{
var ddl = new HtmlSelect();
for (int i = 0; i < controlsToAdd; i++)
ddl.Items.Add((i + 1).ToString());
form1.Controls.Add(ddl);
}
private Int32 NumberOfItems
{
get
{
Int32 timesToRender;
return Int32.TryParse(Request.QueryString["numItems"], out timesToRender) ? timesToRender : 1;
}
}
private Int32 ControlsToRender
{
get
{
Int32 timesToRender;
return Int32.TryParse(Request.QueryString["numControls"], out timesToRender) ? timesToRender : 1;
}
}
private ListType ListToRender
{
get
{
String listType = Request.QueryString["listType"];
if (String.IsNullOrEmpty(listType)) return ListType.DropDownList;
return (ListType)Enum.Parse(typeof (ListType), listType, true);
}
}
}
I tested each of these controls with various inputs, and found the trace to be almost identical in each case. The HtmlOption control nets you a tiny advantage in performance over the DropDownList, but even when rendering 100 of each control with 100 items apiece, the difference is only a few hundredths of a second.
So in the end... stick with the DropDownList control since it has more options available to you. The issue with the ID getting decorated by the ASP.Net runtime can be easily mitigated as shown in the other answers. Also, you can design your JavaScript functions in such a way that they can operate on an ID passed in as a parameter.
function doStuff(strId)
{
document.getElementById(strId); //Straight up, no lime
$get(strId); // Asp.Net Ajax Client Side Framework
$(strId); // JQuery
}
If you do this, then it is easy enough to tie in to a client event (onclick, onmouseover, onmouseout, etc...) in order to reuse your behavior in many places.
Cheers,
Josh