Create a utility to generate your values:
public class Utils { public static IEnumerable<string> GetSequenceEntries(long maxValue) { yield return string.Empty; for(int i=1; i<=maxValue; i++) { yield return i.ToString(); } } }
Then, for the WinForms application, bind it the same way as this:
private void Form1_Load(object sender, EventArgs e) { comboBox1.DataSource = Utilities.Utils.GetSequenceEntries(100).ToList<string>(); }
Or for ASP.NET bind it like this:
protected void Page_Load(object sender, EventArgs e) { ddl1.DataSource = Utilities.Utils.GetSequenceEntries(100); ddl1.DataBind(); }
source share