Interacting two-dimensional electrons confined in a GaAs quantum well exhibit isotropic transport when the Fermi level resides in the first excited (N=1) Landau level. Adding an in-plane magnetic field (B_{||}) typically leads to an anisotropic, stripelike (nematic) phase of electrons with the stripes oriented perpendicular to the B_{||} direction. Our experimental data reveal how a periodic density modulation, induced by a surface strain grating from strips of negative electron-beam resist, competes against the B_{||}-induced orientational order of the stripe phase. Even a minute (<0.25%) density modulation is sufficient to reorient the stripes along the direction of the surface grating.