我如何在与每个按钮点击一次返回一个项目? [英] How do I return one item at a time with each button click?
问题描述
我有我宣布我上面的表格载数组:
I have an array that I declare above my form load:
protected string[] Colors = new string [3] {"red", "green", "orange"};
当我点击这个我提出我想使用的Response.Write();
来打印出红色
对于第一次点击,绿色
我第二次单击它,然后最后橙色
我最后一次单击它。我读<一个href=\"http://stackoverflow.com/questions/25625272/how-do-i-get-next-item-in-array-with-each-button-click\">How我会得到下一个项目在每个按钮阵列点击?以及该用户正在尝试非常相似,我试图做一些事情,但它看起来好像在这种情况下该数组是动态的。
When I click this my submit I want to use a Response.Write();
to print out red
for the first click, green
the second time I click it, then finally orange
the last time I click it. I was reading How do I get next item in array with each button click? and this user is trying to something very similar to what I am trying to do, however it looks as though the array in that case is dynamic.
推荐答案
在会话跟踪它
protected void Page_Load(object sender, EventArgs e)
{
int? count = Session["count"] as int?;
count = (count == null) ? 0 : count;
Response.Write(Colors[count.Value]);
count = (count + 1) % Colors.Length;
Session["count"] = count;
}
这篇关于我如何在与每个按钮点击一次返回一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!