I had to use a different approach:
I set the gridview to have no columns and autogeneratecolumns
to false
.
Then I created a XML with the list of all possible columns (this is a XML, not asp.net markup)
<Grid ID="grdSenha">
<BoundField HeaderText="Status" />
<BoundField DataField="Flg_Imprimiu" HeaderText="Imprimiu?" Visible="True" />
<BoundField DataField="Nom_Localdest" HeaderText="Local Descarga" Visible="True" />
<BoundField DataField="Dsc_Localdest" HeaderText="Descrição" Visible="True" />
<BoundField DataField="Cod_Produto" HeaderText="Cod Prod" Visible="False" />
<BoundField DataField="Dsc_Produto" HeaderText="Descrição Produto" Visible="True" />
<BoundField DataField="Qtd_Transport" HeaderText="Qtde" Visible="True" />
<BoundField DataField="Cod_Transport" HeaderText="Cod Trans" Visible="False" />
[...]
</Grid>
Then, in my code, I'd select from the XML only the columns present in my datasource (using the DataField as key), then create the bound fields accordingly.
It works perfectly.