ArrayList stateList, gdpList, rankList;
public void Page_Load(object sender, EventArgs e)
{
stateList = new ArrayList(); //The state array list
stateList.Add("Delaware");
stateList.Add("Alaska");
stateList.Add("North Dakota");
stateList.Add("Connecticut");
stateList.Add("Wyoming");
stateList.Add("Massachusetts");
stateList.Add("New York");
stateList.Add("New Jersey");
stateList.Add("Oregon");
stateList.Add("Washington");
stateList.Add("Virginia");
stateList.Add("Minnesota");
rankList = new ArrayList(); //The ranking array list for each state
rankList.Add(1);
rankList.Add(2);
rankList.Add(3);
rankList.Add(4);
rankList.Add(5);
rankList.Add(6);
rankList.Add(7);
rankList.Add(8);
rankList.Add(9);
rankList.Add(10);
rankList.Add(11);
rankList.Add(12);
gdpList = new ArrayList(); //The GDP array list for each state
gdpList.Add("61,183");
gdpList.Add("61,156");
gdpList.Add("55,250");
gdpList.Add("54,925");
gdpList.Add("54,305");
gdpList.Add("53,221");
gdpList.Add("53,067");
gdpList.Add("49,430");
gdpList.Add("48,069");
gdpList.Add("47,146");
gdpList.Add("47,127");
gdpList.Add("47,028");
}
void GDP_Click(object sender, EventArgs e)
{
string state1 = State.Text;
for (int i = 0; i < stateList.Count; i++ )
{
if (state1 == stateList[i])
{
Response.Write("The " + stateList[i] + " state GDP is " + gdpList[i] + " and the rank is " + rankList[i]);
}
else if (state1 == stateList[i])
{
Response.Write("The state that you entered is not a part of our state list");
}
}
}
So I have these three arrays. One with twelve states, one with ranking of 1-12, and their GDP in the other array. There is a text box and a button. If you enter say.. Delaware in the text box, then click the button it will generate a label that says: the state, their rank, and their GDP. However, regardless of what state I put in it will always return "the state is not listed" even if it matches the array. I'm assuming that the loop keeps running. So I tried, adding break after each response, that didn't work. Then I tried, adding return after each response, that didn't work either. I tried boolean but couldn't exactly figure it out.