A sulfonated poly-4-vinyl pyridinium (PVPy-IL-B-SO3H) containing an acidic pyridinium/HSO3−ionic liquid moiety was prepared and used as a catalyst for the three-component reaction of malononitrile with 1-alkylindoline-2,3-diones and 1,3-dimethylpyrimidine-2,4,6(1H,3H,5H)-trione or methyl 5-hydroxy-1H-pyrazole-3-carboxylate, leading to methyl 6′-amino-5′-cyano-2-oxo-2′H-spiro[indoline-3,4′-pyrano[2,3-c]pyrazole]-3′-carboxylates or -3,4′-pyrano[2,3-d]pyrimidine]-6′-carbonitrile derivatives under ultrasonic irradiation conditions. The solid catalyst allows easy separation, is cheap, produces high yields under mild conditions, and does not require column chromatography for product isolation and purification.