I need to create an array of images based on user input as shown below.

Now I am creating buttons programatically and setting the image property.
But it is pain as it has bunch of C# code to write.
Is there any better way to achieve this?
Note: On mouse hover on each item in image array it has to show its number in array like 2x1.