The M7 bayonet has been issued w/the M16 since about 1964, the M9 was brought into service in the late 80's/early 90's, it was originally meant for specific issue & not to replace the M7, here's a pic of the M7 (center) & M9 (bottom), the top is the original Colt bayonet for the Ar15/601.
Here's a link to a couple more pics:
http://imageevent.com/willyp/firearmsalbums/uscoltarmalitem16ar15556/m16accessoryitems/bayonets
Either would be correct on an M16A2 but the M7 would be more common, also the M9 is much more expensive if you're looking for an original military issue blade, there are plenty of commercial contract M9's available at this point from the current contractor but these are a later variant (minor differences in mfg, later M9's are made by Ontario & lanCay), for a military issue M9 w/an M16a2 say for the Gulf War era you'd need a Phrobis mfg military contract M9, again there are commercial variants out there & the military originals bring fairly big $, the M7 is much less $, any M7 maker would be correct although Ontario & General Cutlery are both post VietNam M7 contract mfgs.
For more info on the M9 check the M9 bayonet site (simple search, M9 bayonet) & for the M7 ck humes M7 bayonet pg.
Here's a couple pics of my replica A2 w/an M7 & another w/an M9: