I Advice don't caring "How id are generated" but just to know what a id is. This is because the id may depend on the whole path in the ViewModel of the property being rendered in the grid, and also on possible in-line transformation applied, and if
the grid is in a partial view....and so on.
If you are either in a row template or in a column template you can get the id of a field associated say to a property called say "Name", by calling the PrefixedId helper with something like:
Html.PrefixedId("Name") or item.PrefixedId("Name") or similar according to the name of the variable that contain the name of the HtmlHelper that is associated to the template or partial view you are in.
So if we suppose you are in a row template and and you are using an in-line html razor helper as template your code becomes:
HOWEVER YOU MUST PUT THE ABOVE CODE IN THE COLUMN OR ROW TEMPLATE because on outer scoper "Name" is not defined. If you don't kno exactly what a template is please read doc about templates: http://mvccontrolstoolkit.codeplex.com/wikipage?title=Use%20of%20Templates