Cycling is still the primary form of transportation for many Shanghai residents, despite the government's best efforts to discourage it by banning bikes on main roads. Shanghai's frenzied traffic is not for the faint of heart, though fortunately most secondary streets have wide, well-defined bike lanes. The pancake-flat city landscape means that gears just aren't necessary -- take your cue from locals and roll along at a leisurely pace. For relaxed riding, head to the beautiful lanes of the Old French Concession. Pudong roads have far less traffic but also less scenery. If a flat tire or sudden brake failure strikes, seek out the nearest street-side mechanic (they're everywhere), easily identified by their bike parts and pumps.
Few hotels rent bikes (hostels are usually the exception), but you can inquire at bike shops or even corner stores, where the going rate is around Y30 a day, plus a refundable deposit, which is often high enough to cover the cost of the bike itself. Check the seat and wheels carefully prior to accepting the rental, or else you'll be stopping to fix flats all day.
Bicycle lights are nonexistent, so cycle with caution at night. Most rental bikes come with a lock or two, but they're usually pretty low quality. Instead, leave your wheels at an attended bike park -- peace of mind costs a mere Y0.50. Helmets are just about unheard of in Shanghai, though upmarket rental companies like Bodhi Bikes rent them. They charge Y150 or more for their bikes, but they're mountain bikes in great condition. They also organize mountain-biking tours.
If you're planning a lot of cycling, note that for about Y200 you can buy your own basic bike; expect to pay three or four times that for a mountain bike with all the bells and whistles. Supermarkets like Carrefour or the sports shop Decathlon are good places to buy them.
Bike China Adventures has a 17-day bike trip that includes Shanghai, along with other destinations in China.