If during the proceedings, the court finds that it has no jurisdiction, how should it proceed?

Where the court has no jurisdiction, lower courts should simply dismiss the case.  On the other hand, the Supreme Court and the Court of Appeals may refer the case to the court of proper jurisdiction.