Add TextBox.Text to a list using a for loop

后端 未结 3 1468
再見小時候
再見小時候 2021-01-23 19:25

I am trying to take the values in the textboxes, named sequentially from 0-9, and add that to a List using a for loop. I am having problems with the syntax or something.

3条回答
  •  北海茫月
    2021-01-23 19:28

    I suppose that your textbox are named "amtBox" + a number. (The Name property is "amtBox1" as an example)

    In this case you could use

     Control[] t = Controls.Find("amtBox" + i, false);
    

    for a code like this

    for (int i = 0; i <= amt.Count(); i++)  
    {  
        Control[] t = Controls.Find("amtBox" + i, false);
        if(t != null && t.Length > 0)
        {
            amt[i] = int.Parse(t[0].Text);  
        }
    } 
    

提交回复
热议问题