I'm working on a legacy windows forms project which I'm migrating to webforms.
There is a dataset which I bind to a gridview .
I have made all boundfields, so the gridview won't automatically generate the columns. Whenever I bind this dataset to the grid, some columns are missing in the dataset, so it's throwing errors about inexistent columns.
Is there any way to ignore missing columns in bound fields? Like, remove the bound column if it doesn't exist... or just ignore it?
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.