Please post your code inside [as][/as] on this forum so it formats the code.
What have you done so far to debug the issue? You should place trace statements around the areas you suspect something is going wrong and use that to figure out what the problem is. Based on your description and volume of code the problem is far from obvious, it needs debugging.