A few things to control gnats:
1st: Make sure you are getting air flow to the bottom of your plants. You need to try and get the soil dried out at the top.
2nd: You can hit the top with a very dilute bleach solution but I wouldn't do that in soil.. I would use Azamax and do a soil drench. If the problem is real bad, you can foliate it.
3rd: place sand on the top of your grow medium. The adults can't burrow into it and lay their eggs. Any eggs in the soil when they hatch, they won't be able to come out through the soil, and your azamax drench will kill them..
4th: place up some sticky traps to monitor the populations and make sure you are keeping them under control.
If you have wet soggy medium, you will get gnats.. If you don't get enough light and airflow on your medium, it will stay moist and soggy. Some the denser your cannopy, the bigger the gnat problem can be....