Ignore non-existent column in the dataset (linked field)

I am working on a legacy windows project that I am migrating to web forms.

There is a dataset that I bind to a gridview.

I did all the related fields, so gridview will not automatically generate columns. Whenever I snap this dataset to a grid, some columns are missing from the dataset, so it throws errors about non-existent columns.

Is there a way to ignore missing columns in related fields? For example, delete the linked column if it does not exist ... or just ignore it?

+6
source share
1 answer

I had to use a different approach:

I found that gridview has no columns, and autogeneratecolumns is false .

Then I created XML with a list of all possible columns (this is XML markup, not asp.net)

 <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 would select from XML only the columns that are present in my data source (using the DataField key as), and then create the related fields.

It works great.

0
source

All Articles