Quantum optimal control can play a crucial role to realize a set of universal quantum logic gates with error rates below the threshold required for fault-tolerance. Open-loop quantum optimal control relies on accurate modeling of the quantum system under control, and does not scale efficiently with system size. These problems can be avoided in closed-loop quantum optimal control, which utilizes feedback from the system to improve control fidelity. In this paper, two gradient-based closed-loop quantum optimal control algorithms, the hybrid quantum-classical approach (HQCA) described in [Phys. Rev. Lett. 118, 150503 (2017)] and the finite-difference (FD) method, are experimentally investigated and compared to the open-loop quantum optimal control utilizing the gradient ascent method. We employ a solid-state ensemble of coupled electron-nuclear spins serving as a two-qubit system. Specific single-qubit and two-qubit state preparation gates are optimized using the closed-loop and open-loop methods. The experimental results demonstrate the implemented closed-loop quantum control outperforms the open-loop control in our system. Furthermore, simulations reveal that HQCA is more robust than the FD method to gradient noise which originates from measurement noise in this experimental setting. On the other hand, the FD method is more robust to control field distortions coming from non-ideal hardware