---
title: "populate dropdownlist with all numbers in between 2 numbers"  
description: "populate dropdownlist with all numbers in between 2 numbers"  
author: "Anonymous User"  
published: 2014-12-08  
updated: 2014-12-09  
canonical: https://www.mindstick.com/forum/12770/populate-dropdownlist-with-all-numbers-in-between-2-numbers  
category: "asp.net"  
tags: ["c#", "dropdown"]  
reading_time: 1 minute  

---

# populate dropdownlist with all numbers in between 2 numbers

```
<asp:DropDownList ID="ddlAge" runat="server"/> Label ages = (Label)e.Row.FindControl("Ages"); //The value ages returns is different every time but it will be in this format// 3 - 11
```

So i would like to grab the 3 from the [left](https://www.mindstick.com/articles/12768/don-t-be-left-behind-with-the-new-it-revolution) of the dash and then grab the 11 from the [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) of the dash and [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) my [dropdownlist](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework) with the [values](https://www.mindstick.com/forum/327/sum-textbox-values) of 3,4,5,6,7,8,9,10,11 if possible just not sure how to go about doing this.

## Replies

### Reply by Mark Devid

This is in VB, but you can convert it in C#. This is just so that you get an idea as to how you can approach this problem. Here is the code:

```
     Dim ageData() As String = ages.split("-".ToCharArray())      If ageData.Count = 2 AndAlso IsNumeric(ageData(0).Trim) AndAlso IsNumeric(ageData(1).Trim) Then        For i As Integer = CInt(ageData(0)) To CInt(ageData(1).Trim) Step +1           ddlAge.Items.Add(i)        Next     End If
```

### Reply by Anonymous User

You can do this:

```
private IEnumerable<int> GetAgesBetween(string agesText) {    var parts =agesText.Split('-');    var start =int.Parse(parts[0].Trim());    var end =int.Parse(parts[1].Trim());    return
Enumerable.Range(start, 1 + end-start);}
```

You can use that method to retrieve the numbers and use them to populate the drop down list.

Hope it helps


---

Original Source: https://www.mindstick.com/forum/12770/populate-dropdownlist-with-all-numbers-in-between-2-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
