Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to rebuild and repopulate a dynamic gridview with different columns

Posted on 2011-03-10
5
Medium Priority
?
598 Views
Last Modified: 2012-05-11
Good Morning,
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.

Thanks.
0
Comment
Question by:thamilto0410
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:LIONKING
ID: 35094896
Have you tried setting the datasource to nothing and binding the gridview so it displays no data at all, then setting the data source to your new query and then rebinding?
0
 
LVL 1

Author Comment

by:thamilto0410
ID: 35111076
LIONKING -- That did not work but I think I know what I am doing wrong.  I will tell you and you advise please.  I think it is because I have a case statement that executes the results based on the report title chosen but  I am adding the columns for each report without knowing how to dispose of prior built columns.
Tell me if this will fix my problem?  What if I on page load in my if not page.ispostback I created and added  all of the columns I need regardless of the report and then in the case statement based on report title just hid the columns not needed.  Would this work?
0
 
LVL 13

Accepted Solution

by:
LIONKING earned 1400 total points
ID: 35111246
If you have predefined columns for your gridview and then change the datasource at runtime, and the columns of your new datasource don't match the ones you defined (or created) at design time, then your grid will not display the data...

If you don't define any columns at design time, once you set the data source at runtime the gridview will automatically create all the columns that are returned by your query, allowing you to hide/show them at will.

Did you define your columns at design time?

Your solution might work, but you would have to add columns each and every time you change your query or want new data to be available. So I don't advise it...
0
 
LVL 1

Author Closing Comment

by:thamilto0410
ID: 35111643
THANK YOU!!  That was exactly the nudge in the direction I needed.  I did as you suggested (If you don't define any columns at design time, once you set the data source at runtime the gridview will automatically create all the columns that are returned by your query, allowing you to hide/show them at will.)  and it is working beautifully now.
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 35112424
You're welcome... Glad I could help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question