Thanks Balu.You are right.But my requirement is to select the document in the embedded view and then change the status of the selected document according to the value in the text field.
I suspect you would have kept this code in a Action button on your form. So it will always return 0. Create a view action and put the same code on that. Then choose the embedded View property on the form and from Display tab select ‘Show action bar’ and ‘Show selection margin’ options. Now it will show the count of selected documents.