It is not possible to be sure what your problems is: if I include both your code fragments in am app and make senisble decisions as to what the undeclared parts are:
TextBox txtId = new TextBox();
TextBox txtName = new TextBox();
ArrayList al = new ArrayList();
int item;
Then I do not get a compilation error.
How does my code differ from yours?