Here I have created sample that will help you out.
HTML
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=hfDropDownIds]').val("")
});
function getDropDownList(name, id, optionList) {
var combo = $("<select></select>").attr("id", id).attr("name", name).attr("runat", "server").attr("class", "class");
$.each(optionList, function (i, el) {
combo.append("<option>" + el + "</option>");
});
return combo;
}
function Add() {
var Id = parseInt($('[id*=hfDDLId]').val()) + 1;
var ddlId = "ddl" + (Id);
var optionList = [1, 2, 3, 4, 5];
$('[id*=div1]').append(getDropDownList(ddlId, ddlId, optionList));
$('[id*=hfDDLId]').val(Id);
var previousDropDownId = $('[id*=hfDropDownIds]').val();
if (previousDropDownId != '') {
$('[id*=hfDropDownIds]').val(previousDropDownId + ',' + Id);
} else {
$('[id*=hfDropDownIds]').val(Id);
}
return false;
}
function Remove() {
var ddlId = $('[id*=hfDDLId]').val();
$('[id$=ddl' + parseInt(ddlId) + ']').remove();
$('[id*=hfDDLId]').val(parseInt($('[id*=hfDDLId]').val()) - 1);
var previousDropDownId = $('[id*=hfDropDownIds]').val();
if (previousDropDownId != '') {
var Ids = previousDropDownId.split(',');
Ids = $.grep(Ids, function (Id) {
return Id != parseInt(ddlId);
});
var resultIds = Ids.join(',');
$('[id*=hfDropDownIds]').val(resultIds);
}
return false;
}
</script>
<div id="div1" runat="server">
</div>
<input type="hidden" id="hfDDLId" value="0" />
<asp:Button ID="Button1" Text="Add" runat="server" OnClientClick="return Add()" />
<asp:Button ID="Button2" Text="Remove" runat="server" OnClientClick="return Remove()" />
<input type="hidden" id="hfSelectedValue" runat="server" />
<input type="hidden" id="hfDropDownIds" value="" runat="server" />
<asp:Button ID="Button3" Text="Get Value" runat="server" OnClick="GetValue" />
</div>
Code
protected void GetValue(object sender, EventArgs e)
{
string values = string.Empty;
string ids = Request.Form["hfDropDownIds"];
foreach (string id in ids.Split(','))
{
if (!string.IsNullOrEmpty(id))
{
values += Request.Form["ddl" + id] + ",";
}
}
if (!string.IsNullOrEmpty(values))
{
values = values.Remove(values.LastIndexOf(','));
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('DropDownList Values are " + values + "');", true);
}
}
Screenshot
