Sayyiduna Imran bin Husayn (may Allah be pleased with him) said: I suffered from piles, so I asked the Messenger of Allah (peace and blessings be upon him) (about how to pray), and he (peace and blessings be upon him) said: "Pray standing; if you are unable, then sitting; and if you are unable to do that either, then lying on your side."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3659