How to rebuild and repopulate a dynamic gridview with different columns
Posted on 2011-03-10
I need an example or links to an example of a solution for the following:
I have a VB.NET application with an oracle backend. This application has the ability to build 7 different reports. The report chosen is databound to a gridview with autogenerate columns set to false. What I need is when the codebehind is called for any of the reports the gridview dumps its content rebuilds the columns and rebinds with a new report. I need it to dump as the user has the ability to call any one of the reports and one report might have 3 columns and the next report might have 6 columns. They choose the report from a dropdown, select a date range and click GET and the report drops into the gridview and can be viewed, exported to excel or printed.
I have tried leaving the presentation blank except for a panel and building the gridview in the codebehind as well as dropping the gridview onto the aspx in design and setting generate columns to false and then adding the columns in the codebehind and using clear columns. But then the problem is my grid either adds the columns twice or if I use removeat I have had index must be nonnegative error.
I am new to developing in .net and just need some guidance as to the best way to work this out.
I cannot use other means of developing reports like Crystal Reports as even the most experienced developer here has not been able to get it working yet in this environment.
Any assistance whether an example or a link to an example will be greatly appreciated.