Without knowing which error you're actually getting, these things are wrong with the current code:
1. Your template column will appear to the left of the other columns, so compared to the Ordinal in your datasource, there is a +1 offset on all auto-generated columns
2. You should probably check the rowtype in your RowCreated event handler to see if it is a datarow or headerrow, because you will only have the cells in these rows:
e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow
It would help however, to actually see the error message that you're getting. I never understand why people say there's an error message, don't include it in their post, and expect the right solution...