Button doesn't show sprites correctly

So I have a problem.
I have LevelController and in it I want to show all levels from database. They should look different depending by it’s status.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Linq;

public class LevelController : MonoBehaviour {

    public List<string> levels;
    public List<string> obtainedLevels;
    public List<string> userLevels;

    public List<int> levelsInt;
    public List<int> userLevelsInt;

    GameObject template;
    GameObject g;

    public Button levelButton;

    // Start is called before the first frame update
    void Start() {
        template = transform.GetChild(0).gameObject;
        DisplayLevels();
    }

    private void DisplayLevels() {
        levels = DatabaseConnector.instance.GetListLevels();
        obtainedLevels = DatabaseConnector.instance.GetListObtainedLevels();
        ListObtainedLevels();
        TransformLists();
        
        for(int i = 0; i < levels.Count; i++) {
            g = Instantiate(template, transform);
            string ID = GetDataValue(levels*, "ID:");*

if(userLevels.Contains(ID)) {
for(int j = 0; j < obtainedLevels.Count; j++) {
string levelID = GetDataValue(obtainedLevels[j], “LevelID:”);
string status = GetDataValue(obtainedLevels[j], “Status:”);
if(ID == levelID) {
if(status == “done”) {
levelButton.GetComponent().sprite = Resources.Load( “level_gold” );
g.transform.GetChild(0).GetComponent().text = ID;
} else if(status == “active”) {
levelButton.GetComponent().sprite = Resources.Load( “level” );
g.transform.GetChild(0).GetComponent().text = ID;

}
}
}
} else {
levelButton.GetComponent().sprite = Resources.Load( “level_grayscale” );
g.transform.GetChild(0).GetComponent().text = ID;

}
}

Destroy(template);
}

string GetDataValue(string data, string index) {
string value = data.Substring(data.IndexOf(index)+index.Length);
if(value.Contains(“|”)) value = value.Remove(value.IndexOf(“|”));
return value;
}

private void ListObtainedLevels() {
for(int i = 0; i < obtainedLevels.Count; i++) {
userLevels.Add(GetDataValue(obtainedLevels*, “LevelID:”));*
}
}

private void TransformLists() {
for(int i = 0; i < levels.Count; i++) {
string lvl = GetDataValue(levels*, “ID:”);*
levelsInt.Add(int.Parse(lvl));
}
userLevelsInt = userLevels.Select(int.Parse).ToList();
}

}
My problem is when it runs it instantiates template, but with the first element it doesn’t add its sprite from resources folder.

So I think I found the solution 5 minutes after posting question, gut I want to know does my solution is correct.

for(int i = 0; i < levels.Count; i++) {
            
            string ID = GetDataValue(levels*, "ID:");*

if(userLevels.Contains(ID)) {
for(int j = 0; j < obtainedLevels.Count; j++) {
string levelID = GetDataValue(obtainedLevels[j], “LevelID:”);
string status = GetDataValue(obtainedLevels[j], “Status:”);
if(ID == levelID) {
if(status == “done”) {
levelButton.GetComponent().sprite = Resources.Load( “level_gold” );
g = Instantiate(template, transform);
g.transform.GetChild(0).GetComponent().text = ID + “Done”;
} else if(status == “active”) {
levelButton.GetComponent().sprite = Resources.Load( “level” );
g = Instantiate(template, transform);
g.transform.GetChild(0).GetComponent().text = ID + “active”;

}
}
}
} else {
levelButton.GetComponent().sprite = Resources.Load( “level_grayscale” );
g = Instantiate(template, transform);
g.transform.GetChild(0).GetComponent().text = ID;
}
}

if it works then it’s correct, doesnt matter what we think