They build another dam – a temporary structure known as a cofferdam
Cofferdams can be made out of pretty much anything, like heavy stone, but can also be pretty elaborate structures all on their own.
This one was made by driving piles into the riverbed, then putting sheet metal between the piles.
Cofferdams aren’t built to take the full load of the finished dam. They will hold back or divert some of the water and they won’t be as sturdy. For the Hoover Dam, the cofferdams diverted the river into a long tunnel that took the water past the dam site during construction. As the dam was finished, the tunnel was closed and the water backed up behind the finished dam instead.