It was most likely an INVERSE BATTLE.
Those types of battle, as the name implies, make it so a type that would be resistant or immune to another type is now weak to that type instead, meaning your Swampert would now be affected by electric moves and not by grass moves.
You could get into those types of battles with the Proprietor Inver in the Inverse Battle Stop in Mauville City, as well as in a Secret Base if it is set to have Inverse Battles using the Proclamation.
It would help to know a bit more details tho, such as if you were playing offline or online, and what 'mon were you facing, because it could also be due to an ability (but it's unlikely, because abilities such as Mold Breaker don't affect effectiveness of types in that way).
Here are more info about Inverse Battles:
http://bulbapedia.bulbagarden.net/wiki/Inverse_Battle
Let me know if this helped!