Using select , you can create an array with numbers to skip and execute a for loop to write options :
int minNumber = 0; int maxNumber = 10; int[] skipThese = { 5, 7 }; for (int i = minNumber; i <= maxNumber; i++) { if(!skipThese.Contains(i)) Response.Write(String.Concat("<option value=\"", i, "\">", i, "</option>")); }
You can do this with a razor or any other way to output HTML.
You can also do this with jQuery, dynamically following the same idea:
$(document).ready(function() { var minNumber = 0; var maxNumber = 10; var skipThese = [5, 7]; for (var i = minNumber; i <= maxNumber; i++) { if ($.inArray(i, skipThese) == -1) $('#selectListID').append("<option value=\"" + i + "\">" + i + "</option>"); } });
Edit: Or you can use the C # code above on an aspx page and load it using AJAX from the page:
Create a selection box on the page:
<select name="numPicker" id="numPicker"> <option>Loading...</option> </select>
In the script on this page, you can use jQuery ajax() to retrieve data and populate <select> :
$(document).ready(function() { var numPickerSelect = $("#numPicker"); $.ajax({ url: 'url/to/page.aspx', type: 'post' success: function(data) { numPickerSelect.find('option').remove();
source share