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
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
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?