Yes, you can. If you were to take a set of magnets out into space, far away from any planets, they would work exactly the same way as they do on the ground (they just wouldn’t fall if you let go of them).
The only gravity then would be the very little bit between the magnets, and also you if you're up there too. /mw
(published on 10/22/2007)