Electrostatic interactions may promote or abate polyelectrolyte adsorption onto a charged surface depending on a number of interrelated factors including the surface and polymer charge densities, the salt concentration, and nonelectrostatic interactions such as van der Waals and hydrophobic forces. Even without the nonelectrostatic interactions, the electrostatic behavior of polyelectrolyte systems is often counterintuitive and cannot be explained with conventional theories of polymers or simple electrolytes. In this work, a nonlocal density functional theory (NLDFT) and Monte Carlo simulations are used together to investigate polyelectrolyte adsorption at both oppositely charged and like-charged surfaces (one due to the direct electrostatic attraction and the other due to counterion correlations). The simulation results provide a stringent test of the numerical performance of the NLDFT, in particular for systems containing multivalent counterions where electrostatic correlations are important. A systematic study of the effects of ion valence, salt concentration, and polyion chain length reveals that polyelectrolyte attraction to an oppositely charged surface is nearly a neutralization effect, little influenced by the polyion chain length and counterion valence. Neither the surface mean electrostatic potential nor the integrated local charge density shows no significant sign of charge inversion. Both theory and simulation predict polyelectrolyte adsorption onto a like-charged surface when the system contains multivalent counterions. In that case, the surface excess is sensitive to the surface charge density, the counterion valence, and the salt concentration. The surface mean electrostatic potential shows a clear evidence of charge inversion when two layers of like charges are mediated by multivalent counterions. The theoretical investigations indicate that most likely, the electrostatic correlation mediated by multivalent counterions is responsible for the layer-by-layer assembly of oppositely charged polyelectrolyte films.