This is a migrated thread and some comments may be shown as answers.

Report not showing data when datasource set to datatable in code-behind

8 Answers 644 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 2
James asked on 10 Dec 2008, 03:51 PM
I have a pop-up web page that shows Product information and have added a print button to the page that allows the user to print this info.  I do not want a report viewer to show when the user clicks this Print button, just open the print dialog, user makes choices and then prints the report.
I have the report viewer on the same page that shows the Product Information in a hidden <div> tag, like this:
    <div style="display:none;">  
        <telerik:ReportViewer ID="ReportViewer1" runat="server">  
        </telerik:ReportViewer> 
    </div> 

All default properties have been taken for the ReportViewer, nothing has been changed.  The report datasource is set in the code-behind (see code below).

When the user clicks on the Print button this is the code that is executed:
    Protected Sub btnPrint_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnPrint.Click  
        Try 
            Me.ReportViewer1.Report = New ShowPartInfoRpt  
            Me.ReportViewer1.Report.DataSource = Me._ProductInfo  
            Dim printScript = String.Format("{0}.PrintReport();"Me.ReportViewer1.ClientID)  
            Me.ClientScript.RegisterStartupScript(Me.GetType(), "ReportPrint", printScript, True)  
        Catch ex As Exception  
           'Generic error handling routine here, not shown  
        End Try 
    End Sub 

So I am setting the report viewer source to the report, then set the datasource for the report to a datatable. This datatable has 1 row in it.  I have stopped the code in debug mode and see the values in the datatable.  When the print dialog appears, the adobe preview window shows nothing, and printing the report prints a blank report.

What am I missing?

Thanks!

8 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 11 Dec 2008, 07:55 AM
Hi James,

As I've shown in the attachment from your previous post "WebService as DataSource", DataTable works correctly as DataSource as any other of the supported sources would do. I've used the project from this thread and modified it to bind the report on the button click handler and it works as expected. Whatever the problem is, it is something else on your end.

Regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 2
answered on 11 Dec 2008, 02:07 PM

Steve,
Thanks for your response.
First, I wasn't questioning that a datatable could be a viable DataSource for a report.  I do follow-up on my posts and believe I responded that I appreciated the help, which means that I understand that a DataTable can be used as a datasource for a report, and also used the response to solve my original problem.

Second, I know it is something on my end, but I am unable to figure out what it is, hence the reason for the post.  Most issues that people post about on here are on their end, and that is due to lack of expertise on the product, which is the reason we post here about our issues.

 

Here is what I have tried since my original post.

I commented out the 2 lines that create the printScript and then register the script for startup.  I then made the <div> tag visible that contains the reportviewer so that now the viewer is visible on the pop-up.  When clicking the print button on the page, the page is reloaded from the server as it should be and the viewer now shows the report correctly after the "Generating report" process dialog is completed.  Now when I click on the Print button in the tool bar and Adobe print dialog appears, the preview window is blank.  Of course, clicking the 'OK' button on the print dialog to print the report produces a blank report. 

One additional thing that I left out of my original post, that I have decided is probably important information, and is probably causing the issues of not being able to print the report.  The report contains several PictureBox controls on it, which get loaded from the datatable.  The datatable does not contain an actual image, it contains a HTTP path to an image.  Not for sure if this is an issue or not, but thought it was worth mentioning.

Please let me know if you have any additional questions/comments that will help me get this resolved.

Thanks.

0
Steve
Telerik team
answered on 11 Dec 2008, 02:55 PM
Hi James,

Since you have explicitly added DataTable as DataSource in the thread's title, I assumed that you had doubts that the type of datasource is the culprit here and hence pointed you to your previous thread which uses DataTable. I did not mean to question anything else, so please excuse me if that is the impression you got.
As for the issue, you can try setting up the Report in the Page_Load eventhandler and see if that makes a difference. The data that comes from the database should not be relevant here and even if there was a problem with the picturebox items, the other content should be visible. To isolate the issue further, you can prepare unbound report with static data in it and test to see what happens.
If still having problems, please zip and send us your report in support ticket for us to investigate.

Regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 2
answered on 11 Dec 2008, 03:30 PM

Steve,
My apologies for an inaccurate subject line.

Any thoughts on why when I set the reportviewer to be visible and click the "print" report button on the page (not the one in the viewer bar), that the reportviewer shows the report with the correct data, but that when I click the "print" report button on the viewers toolbar nothing appears in the print preview window or prints?
I did do some additional research about URLs and discovered that this shouldn't be a problem.
The pictureboxes have their value set to something like this:  =Fields.ImgMainURL, which of course is a column (datatype of string) from my datatable that I am setting to the datasource, and contains a URL similiar to this: http://www.keystone-auto.com/mainimg.jpg

I did try your suggestion of moving the report setup code into the page_load event, and the results are the same.  I see the report in the viewer, but clicking the viewer's report button produces a blank report in the preview window.

I will create a static report and repeat the test, and after doing this will create a support ticket with the report that I am having issues with.

 

Thanks!

0
James
Top achievements
Rank 2
answered on 11 Dec 2008, 03:48 PM
Steve,
I created a static report and set the viewer to this report, and it shows up correctly in the viewer and in the print dialog print preview, and also prints correctly, so obviously something is wrong with my report in how the data is bound between when it is in the viewer and clicking the viewer's button to print the report.

I am going to try a few things first, and if unable to to come up with a resolution I will then open a support ticket and attach the report.

Thanks!
0
James
Top achievements
Rank 2
answered on 11 Dec 2008, 04:40 PM
Steve,
Thanks for the suggestion of using a static report.  This made me re-evaulate the data contained in my datatable that is bound to the report.  I have 7 pictureboxes on the report which may or may not have a URL in the bound data column from the datatable.  So I set the datacolumn for an image to String.empty if the image URL was not present, and this made the report start showing in the print dialog preview window. 
Now I am having a problem with the picture boxes that a value of string.empty.  In the print dialog preview window and when you print, I can see the following errors for the picture box showing up:

An errorhas occurred while processing PictureBox "name of picturebox control":  Access to the path 'project path is shown here' is denied.
Would this error go away if in the detailsection ItemDataBound event I set the visible status of these pictureboxes to false if there is no image URL for this specific picturebox?

Thanks for your help!
0
James
Top achievements
Rank 2
answered on 11 Dec 2008, 11:02 PM
Steve,
We have corrected the data that is coming from the web service so that the code producing the report receives an image url all the time, either the valid image matching the data, or a no image data path.  This fixed the issue that I was having.  It seems the report does not like to have a string column equal to null values when binding to a report that contains picture boxes.

Thanks!
0
Steve
Telerik team
answered on 15 Dec 2008, 12:01 PM
Hi James,

I am glad that you have figured out how to address the problem you've encountered. Another possible solutions is using the IsNull and IIf() built-in functions.

Greetings,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
James
Top achievements
Rank 2
Answers by
Steve
Telerik team
James
Top achievements
Rank 2
Share this question
or