instantiate a button in a panel in new uGUI

I have a List in a script which is being increased every now and then. I would like to instantiate a button in a panel with a grid layout for every string in the list. Something like:

foreach(int i=0; i < list.Count; i++){
    button.text.text = list*;* 

I’m not sure how to say it’s got to be in the panel though.

I think you want to put them inside the layout right?

If it’s right, here’s the code:

 public GameObject yourGridLayout;
    //Here i put on click but you need to put your method.
    void OnClick(){
    for(int i = 0; i < list.Count; i++){
     var buttonInstantiate = Instantiate(button);
     buttonInstantiate.text = list*;*

buttonInstantiate.transform.gameObject.parent = yourGridLayout.transform;


Hope it helps, remember that i missed the class on the script.