How do I return one item at a time with each button click?

后端 未结 4 1046
南笙
南笙 2021-01-19 17:23

I have an array that I declare above my form load:

protected string[] Colors = new string [3] {\"red\", \"green\", \"orange\"};

When I clic

4条回答
  •  灰色年华
    2021-01-19 17:38

    Track it in a session

     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;
        }
    

提交回复
热议问题