Trout are indeed capable of swimming upstream. Biologically speaking, most trout swim upstream in response to sex hormones when it is time for them to spawn. This causes them to first seek highly oxygenated water to fight the current. There is also a fairly complicated evolutionary history behind the trait of trout swimming upstream. This fish initially started out as a freshwater fish. However, as time went on their ancestors moved into brackish rivers and finally into oceans. Because they evolved in freshwater, the eggs could still only survive in fresh water. As a result every year the trout ancestors were required to move from the ocean back into the freshwater when it was time to reproduce.
However as trout moved through the oceans they gradually began to discover new rivers and streams located in new countries, as well as streams that had just formed on their own with time. The trout began to breed in these new streams and some of them never moved back to the oceans. As a result today there are a lot of different types of trout and while most do still move back to the oceans after they hatch, some live their entire lives in freshwater environments. Some species of trout such as the Steelhead are able to do either, with some individuals returning to the oceans while others starve in the freshwater where they are born.
Because all trout ancestors evolved to swim from the ocean back up the freshwater streams, most species of trout can still be found doing so today. Even those trout that have never left the freshwater begin to feel the urge to move and swim higher upstream. Some trout species never swim upstream, and instead opt for clean water which many times is located downstream.