How do the wheels of a train have sufficient grip on a metal track? I mean both of the surfaces are smooth (and not flexible) and it is okay if there is no inclination, but how about on an inclined track?
Sliding is prevented by friction and the friction force is equal to the product of the weight - the perpendicular force - and the dimensionless coefficient of static friction.
The coefficient of static friction between steel and steel can be as high as 0.78 so the angle would have to be hugely non-horizontal for the train to slide. And a lot of acceleration may be added, too.
The lowest coefficient of static friction in wet and greasy conditions may be 0.05 which is approximately the angle in radians where one could start to get worried. It is just 3 degrees and if there's lot of oil everywhere on the tracks, the train may get unsafe already for these small angles. However, in reality, the coefficient never drops this low and 15 degrees is usually a safe angle.
Note that the coefficient of static friction is higher than the coefficient of kinetic friction so the hardest thing is to start the sliding. Once the train starts to slide, it is more likely that it will continue to do so.
All the text above was about the sliding - the stability in the front-rear direction. The stability in the left-right direction is guaranteed by the shape of the wheels:
The reason trains stay on track is because the wheels are not cylindrical, but conical. See Feynman's explanation here: http://www.youtube.com/watch?v=y7h4OtFDnYE