Here is what im trying to accomplish and maybe an array is not the way to do it. I have a form that allows you to complete a form and submit that data. You can then continue submitting different data.. one of the fields(currently a textbox) is to assign
an available number..
So what i was thinking since this can get pretty large quickly, i would like to change the textbox to a dropdown of all available numbers that havent been used yet..
What this form does, is allow the client to create questions and provide possible answers and chose what number question it is to show on the printed form.
Since this is based on form name, currently my validation is checking the form name and number to see if its alreayd used, if so then they cant submitt the form..
Instead of the extra step for the client, id like to just dynamically update the dropdown with all available numbers..
So first time it loads it has 100 or whatever number of possible questions in the drop down( so dropdown list with numbers 1-100)
You select your options, you can chose a number or just leave it on the default and submit..
Now next time around when you creat another question, the drop down now has only 2-100, since 1 was used previously and so on..
So as you submit new data, the list is reduced to available numbers only..
is an array the way to go working together with a datatable or is there a better way to do this.. any links or suggestions on such a thing would be great..
thanks..
Intermediate ASP.net User, Using VS2008/VS2010 with C# and SQL2005, SQL2008, Silverlight 3
---------------------
Mark as Answered if it helped
Here is what i have so far, i built the list and array and the dropdown now has a predefined number of items.. 150
I want to filter out the ones im returning in my arraylist.. what am i doing wrong that i keep getting error:
{"Specified cast is not valid."} on the foreach line
List<int> list = new List<int>();
ArrayList dsQuestionNumber = new ArrayList(dac.getQuestionNumberList(txtFormName.Text));
for (int i = 1; i < 151; i++)
{
list.Add(i);
}
foreach (int s in dsQuestionNumber)
{
list.Remove(s);
}
int[] terms = list.ToArray();
cbQuestionNumber.ItemsSource = terms;
Intermediate ASP.net User, Using VS2008/VS2010 with C# and SQL2005, SQL2008, Silverlight 3
---------------------
Mark as Answered if it helped
List<string> list = new List<string>();
ArrayList dsQuestionNumber = dac.getQuestionNumberList(txtFormName.Text);
for (int i = 1; i < 151; i++)
{
list.Add(i.ToString());
}
foreach (string s in new System.Collections.ArrayList(dsQuestionNumber))
{
list.Remove(s);
}
string[] terms = list.ToArray();
Intermediate ASP.net User, Using VS2008/VS2010 with C# and SQL2005, SQL2008, Silverlight 3
---------------------
Mark as Answered if it helped
Marked as answer by cubangt on May 04, 2012 06:45 PM
cubangt
Contributor
3052 Points
2402 Posts
Build array of numbers MINUS numbers returned in datatable
May 04, 2012 04:13 PM|LINK
Here is what im trying to accomplish and maybe an array is not the way to do it. I have a form that allows you to complete a form and submit that data. You can then continue submitting different data.. one of the fields(currently a textbox) is to assign an available number..
So what i was thinking since this can get pretty large quickly, i would like to change the textbox to a dropdown of all available numbers that havent been used yet..
What this form does, is allow the client to create questions and provide possible answers and chose what number question it is to show on the printed form.
Since this is based on form name, currently my validation is checking the form name and number to see if its alreayd used, if so then they cant submitt the form..
Instead of the extra step for the client, id like to just dynamically update the dropdown with all available numbers..
So first time it loads it has 100 or whatever number of possible questions in the drop down( so dropdown list with numbers 1-100)
You select your options, you can chose a number or just leave it on the default and submit..
Now next time around when you creat another question, the drop down now has only 2-100, since 1 was used previously and so on..
So as you submit new data, the list is reduced to available numbers only..
is an array the way to go working together with a datatable or is there a better way to do this.. any links or suggestions on such a thing would be great..
thanks..
---------------------
Mark as Answered if it helped
cubangt
Contributor
3052 Points
2402 Posts
Re: Build array of numbers MINUS numbers returned in datatable
May 04, 2012 05:32 PM|LINK
Here is what i have so far, i built the list and array and the dropdown now has a predefined number of items.. 150
I want to filter out the ones im returning in my arraylist.. what am i doing wrong that i keep getting error:
{"Specified cast is not valid."} on the foreach line
List<int> list = new List<int>(); ArrayList dsQuestionNumber = new ArrayList(dac.getQuestionNumberList(txtFormName.Text)); for (int i = 1; i < 151; i++) { list.Add(i); } foreach (int s in dsQuestionNumber) { list.Remove(s); } int[] terms = list.ToArray(); cbQuestionNumber.ItemsSource = terms;---------------------
Mark as Answered if it helped
cubangt
Contributor
3052 Points
2402 Posts
Re: Build array of numbers MINUS numbers returned in datatable
May 04, 2012 06:45 PM|LINK
List<string> list = new List<string>(); ArrayList dsQuestionNumber = dac.getQuestionNumberList(txtFormName.Text); for (int i = 1; i < 151; i++) { list.Add(i.ToString()); } foreach (string s in new System.Collections.ArrayList(dsQuestionNumber)) { list.Remove(s); } string[] terms = list.ToArray();---------------------
Mark as Answered if it helped
Paul Linton
Star
13403 Points
2531 Posts
Re: Build array of numbers MINUS numbers returned in datatable
May 05, 2012 02:36 AM|LINK
Assuming that getQuestionNumberList returns something of type IEnumerable and similarly for dsQuestionNumber then
cbQuestionNumber.ItemsSource = dac.getQuestionNumberList(txtFormName.Text).Except(dsQuestionNumber);
is all you need.
Linq - removes even stubborn loops