No, dogs don’t only do their business in the grass, but that is where most of them are taught to go. The grass feels different on their feet so it’s easier to potty train them with grass as they can distinguish the grassy areas from the hard floored places.
However, you can use a grate or litter box with success. It just might take a little longer to train them that it is okay for them to do their business there.