How to hide empty columns in the gridview

I have a table with around 50 columns (propably not the best design but it has to stay like this). I’d like to set up the gridview to show only not empty columns for each specifi foreign key.

Eg. for foreigh key x I might have only 5 columns with data in it, and would like to see only these 5 columns in the grid view.

I know there is visible property in the gridview but doing all these if’s for 50 attributes would be a nightmare. Any advise ?

Best regards
Lukasz

Hum… for 50 of them might as well do it manually with find and replace. The other method is to use javascript where you search each column and add a hidden class to the columns if they are empty. But by the time you debug and trial it, might as well do it manually. with headOptions