I found the problem. If you create GridTemplateColumn at runtime, you have to build the grid in PageInit event.
Creating columns on PageLoad when
!Page.IsPostBack is not a problem for all column types except
for GridTemplateColumns. In order to persist their ViewState you need to
generate your grid completely in the code-behind
(on PageInit). Thus the template controls will be retained as
they will be instantiated before LoadViewState event of the
(Grid help document)"