\documentclass[]{article}
\usepackage{listings}
\usepackage{lstlinebgrd} % see http:/www.ctan.org/pkg/lstaddons
\usepackage{xcolor}

\begin{document}

\begin{lstlisting}[language=C,basicstyle=\ttfamily,linebackgroundcolor={\ifodd\value{lstnumber}\color{green}\fi}]
	foo
	bar
	baz
	quux
\end{lstlisting}

% \ifnum\value{lstnumber}>9
% \ifnum\value{lstnumber}<25
% 	   \color{yellow!40}
% 	   \fi
% \fi

\begin{lstlisting}[language=C,basicstyle=\ttfamily,linebackgroundcolor={
	\ifnum\value{lstnumber}=1
		\color{green}
	\else 
		\ifnum\value{lstnumber}=2
			\color{green}
		\else 
			\color{red}
		\fi
	\fi}
	]
	foo
	bar
	baz
	quux
\end{lstlisting}


\end{document}

% lstlinebgrd.sty
% %    \begin{macrocode}
% %<!COPYRIGHT>
% \ProvidesPackage{lstlinebgrd}[%
% %<!DATE>
% %<!VERSION>
% %<*DRIVER>
%     2099/01/01 develop
% %</DRIVER>
%     Provides 'listings' options to color the background of lines]
% %    \end{macrocode}
% %    \begin{macrocode}
% %
% \RequirePackage{listings}
% \RequirePackage{xcolor}

% % Patch line number key to call line background macro
% \lst@Key{numbers}{none}{%
%     \def\lst@PlaceNumber{\lst@linebgrd}%
%     \lstKV@SwitchCases{#1}%
%     {none:\\%
%      left:\def\lst@PlaceNumber{\llap{\normalfont
%                 \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\%
%      right:\def\lst@PlaceNumber{\rlap{\normalfont
%                 \kern\linewidth \kern\lst@numbersep
%                 \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
%     }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}

% % New keys
% \lst@Key{linebackgroundcolor}{}{%
%     \def\lst@linebgrdcolor{#1}%
% }
% \lst@Key{linebackgroundsep}{0pt}{%
%     \def\lst@linebgrdsep{#1}%
% }
% \lst@Key{linebackgroundwidth}{\linewidth}{%
%     \def\lst@linebgrdwidth{#1}%
% }
% \lst@Key{linebackgroundheight}{\ht\strutbox}{%
%     \def\lst@linebgrdheight{#1}%
% }
% \lst@Key{linebackgrounddepth}{\dp\strutbox}{%
%     \def\lst@linebgrddepth{#1}%
% }
% \lst@Key{linebackgroundcmd}{\color@block}{%
%     \def\lst@linebgrdcmd{#1}%
% }


% % Line Background macro
% \newcommand{\lst@linebgrd}{%
%     \ifx\lst@linebgrdcolor\empty\else
%     \rlap{%
%         \lst@basicstyle
%         \color{-.}% By default use the opposite (`-`) of the current color (`.`) as background
%         \lst@linebgrdcolor{%
%         \kern-\dimexpr\lst@linebgrdsep\relax%
%         \lst@linebgrdcmd{\lst@linebgrdwidth}{\lst@linebgrdheight}{\lst@linebgrddepth}%
%         }%
%     }%
%     \fi
% }
% %    \end{macrocode}