I know that integration of parts can be used on a single integral: $$\int \frac{df}{dx} g \,dx = fg - \int f\frac{dg}{dx} \,dx$$
For a triple integral with a gradient operator, is the following operation legitimate? $$\iiint_V \nabla(f)g \,dV \,=?\, fg - \iiint_V f\nabla(g) \,dV$$ If not, how would one simplify the expression on the left? Please explain.
Note that we have
$$\begin{align} \int_V \nabla(f)\,g\,dV&=\int_V \left( \nabla(fg) -f\nabla(g)\right)\,dV\\\\ &=\oint_S fg \hat n\,dS- \int_V f \nabla(g) \,dV \end{align}$$
where $S$ is the boundary of $V$ and $\hat n$ is the outward unit normal of $S$.