The optimized structure parameters, electron density of states, energy band structures and optical bandgaps of the TM0.125Zn0.875O (TM=Be, Mg) alloys and Ga-doped TM0.125Zn0.875O are calculated and analyzed by using the ultra-soft pseudopotential approach of the plane-wave based upon density functional theory. The theoretical results show the Ga-doped TM0.125Zn0.875O materials are easily obtained and their structures are more stable. The Ga-doped TM0.125Zn0.875O are good n-type materials and their energy bandgaps are determined by Ga 4s states of the conduction band minimum and O 2p states of the valence band maximum. Compared with the TM0.125Zn0.875O alloys, the optical bandgaps of Ga-doped TM0.125Zn0.875O become wider due to the Burstein-Moss shift and many-body effects, which is consistent with previous experimental data. The Ga-doped TM0.125Zn0.875O materials are suitable as TCO films for the UV and deep UV optoelectronic device.