Generate the HTML grid programmatically