Let $(X,\mu)$ and $(Y,\nu)$ be $\sigma$-finite measure spaces such that $L^2(X)$ and $L^2(Y)$ . Let $\{f_n\}$ be an orthonormal basis for $L^2(X)$ and let $\{g_m\}$ be an orthonormal basis for $L^2(Y)$. I am trying to show that $\{f_n g_m\}$ is an orthonormal basis for $L^2(X\times Y)$. So far, I have attempted to show that if $h\in L^2(X\times Y)$, then
$h(x,y) = \sum_m \sum_n \langle h , f_n g_m\rangle = \sum_m \sum_n \int_X \int_Y h(x,y) f_n(x)g_m(y) d\nu d\mu$.
Using the fact that $x\mapsto h(x,y) \in L^2(X)$ for almost every $y$ and similarly for $y\mapsto h(x,y)$, I can obtain
$h(x,y) = \sum_{m=1} ^\infty (\int_X [\sum_{n=1} ^\infty (\int_Y h(x,y)g_n(y) d\nu)g_n(y) f_m(x)] d\mu) f_m(x)$.
However, I am unable to justify passing the summation outside the integral. Any suggestions?