-2

I don't know how to solve this please help me I have 2 texboxes that you type in 2 numbers like:

From: 5

To: 10

Button that sends it to the dropdown

Dropdownlist shows

5,6,7,8,9,10
user692942
  • 16,398
  • 7
  • 76
  • 175
Mild
  • 1

1 Answers1

1

Since you didn't show us any code, I wrote my own. Let's call your textboxes as TextBox1 and TextBox2.

On Click event of your Button, calculate these values as an integer first.

int start = Int32.Parse(TextBox1.Text);
int end = Int32.Parse(TextBox2.Text);

After that, check your end is bigger than start and take range with Enumerable.Range with your values;

if(end > start)
   IEnumerable<int> list = Enumerable.Range(start, end - start + 1);

And finally, bind this list to your dropdownlist like;

DropDownList1.DataSource = list;
DropDownList1.DataBind();

If it is needed, define it's DataTextField and DataValueField properties as well.

Also look at PostBack concept: What is a postback?

Community
  • 1
  • 1
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • Probably you should add some explanation when we have PostBack and in the case when we need to Rebind the DropDownList. – mybirthname Jan 17 '15 at 11:55