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

后端 未结 4 1013
南笙
南笙 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:53

    You have to store the number of clicks in your ViewState and increase it by one in your button's click event handler.

    private int NumberOfClicks
    {
       get { return (int)(ViewState["NumberOfClicks"] ?? 0 );
       set { ViewState["NumberOfClicks"] = value; }
    }
    
    
    protected void btn_Click(object sender, EventArgs e)
    {
       if(NumberOfClicks < colorArray.Length)
       {
               //write to response colorArray[NumberOfClicks];
               NumberOfClicks += 1;
       }
    }
    

提交回复
热议问题