I want to display the results of a pivot table in a datagrid. I have defined the static columns in the <Columns> section as bound columns. Since I don't know what the pivoted columns are going to be (they are data dependent) I have to dynamically add them in the code before doing the data binding. That works ok, but on postback is where it gets ugly. What I have to do in the Page_Init is recreate the dynamic columns because they won't be preserved in the postback. Unless they are recreated in the Page_Init event, the sort event will not fire when the header of one of the "pivot" (i.e. dynamic) columns is clicked. This means I have to save those column names in a Session variable, so I know what I need to recreate on the postback. That handles the problem with sorting on a pivot column. If instead of doing a sort, the user changes any of the criteria, I get the new set of data and I transform it into a new pivot table. Now I have to delete all of the pivot columns in the datagrid from the previous request. It seems that there are a whole lot of issues to deal with for dynamically-created columns. Is there an easier way? Am I missing something here? Thanks.
Start Free Trial