I have seen a couple of different ways of going about it. One is to weld an eye on the tailgate and one in the bedside right below it. They used a metal pin with a head that dropped through the eyes.
On another one, they used the male part of a seat belt buckle on the tailgate, and the female (push button) part on the bed. Close the gate and latch the buckle...