you cannot and should not write code in ListPages
for list pages you always put code in interaction class
following is an example
msdn.microsoft.com/.../cc570334.aspx
Note: I will not be interested to solve your specific issue by coding for you. above response is just a general suggestion, to provide a guideline