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

Filling Unbound Fields on a Crystal Report in ASP.NET

Posted on 2006-07-05
Last Modified: 2010-05-18
I  have  a Crystal Report created with unbound fields.  I want to be able to use ASP.NET to update the crystal report in my code with data from a sql database.

I have never worked with crystal reports before.

I need to know how to:
1 - Access the report in my code.
2 - Update the unbound fields
3 - Save the report as a pdf

I am so frustrated!  Can somebody please please help me?!
Question by:proten
  • 7
  • 5
LVL 16

Expert Comment

ID: 17047654
My suugestion is to get your data from DB using ASP.NET code and then pass the data into the crysytal report as reprot parameters.

For exporting to PDF, see http://www.c-sharpcorner.com/Code/2004/May/ExportCrystalReportInASPNET.asp


Author Comment

ID: 17047775
I can get the data no prob in my ASP.NET code.

I have the fields that I need to use in my report, now what?

How do I access the report in my code and how do I set the parameters to fill the data?
LVL 16

Expert Comment

ID: 17048237
Add a parameter field in the crystal report and then you can drag the parameter field onto your crystal report.

To assign value to the parameter, you can refer

Hope that helps

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.


Author Comment

ID: 17050532
I think I need to fill the fields dynamically in the background.

I'll explain my scenario:

I am creating a packing slip/s.  When a user enters say a customer number and some other information on the asp.net front end, I will validate the info and then populate one or more of the template I have in my report.  I will be getting the data from 3 different tables and one will be repetitive.

Address Info is one record on the address table
Customer Id info is one record on the cust table
Order Info is multiple records on the order table (I display these as a list)

I will create one packing slip per customer but there may be a few customers.  

The end result is a report with 1 or more pages.  Each page containing the information for one customers order that may contain many items.

The way I figured I'd do it is create an asp.net screen that has input fields for the key information.  Then in the code-behind I can get the data from the db and manipulate it and in my code set each field to an unbound field in the crystal report that will be generated in my code.  I already have the crystal report template created so I want to "read" it and fill in the "blanks" in my program.

Author Comment

ID: 17050550
I guess my question is that I already have the template created and set out in a .rpt file, how do I read it in my program and fill the fields?
LVL 16

Expert Comment

ID: 17051342
It seems to me you are finding a way to assign a value to a field inside the crystal report from outside.  I doubt if it is possible!?

I hope I understand your scenario correctly.  You generate the packing slip probabaly based on an order which contains customer Id and other items ordered.  Then I will pass just the order Id to the crystal report and then draw the necessary data from DB by the code (actually a DB query) inside crystal report.

Alternatively, you can compose a dataset in ASP.NET which contains all the necessary data of your packing slip and then pass the whole dataset to the crystal report as datasource.


Author Comment

ID: 17052526
I dont think the first option will work because the top portion of the form is regular table data (one record per form) but included on the form is a detail table of up to 10 items per form that is one record per line from one datatable.

The second option makes more sense.  I can create a dataset and name each of the detail lines a different field name.  

I still dont know how to open the file with the template in my asp.net code and set the dataset as the datasource for the crystal report.  Also, will I be able to create multiple pages of the same template (i.e. 5 packing slips for different customers)?
LVL 16

Expert Comment

ID: 17055475
The first option is feasible when you use grouping in crystal report.

You have to select all related tables in the crystal report and then use the orderId parameter as the selection criteria.
Group the record by the orderId field and then put the customer name, address stuff in the group header section and put the order lines (item code, qty, etc) in the details section.  (Actually you can choose not using grouping and simply put the cusotmer data in the report header section but I prefer grouping because it allows you to print multiple slips at a time)

For using dataset in CR, please refer to these articales

For having multiple copies of a report, you can create a crystal report and then add the template as multiple subreports.


Author Comment

ID: 17074194
Hope you had a nice weekend.

Okay, I have figured out how to
open the report using rpt.load()
access and set the fields using cr.DataDefinition.FormulaFields("FldName")
and save it to pdf using cr.ExportToDisk()

So now I can create a report with one page.  Now I need to create multiples of the same page in the same document.

Subreport sounds like the right idea.  How do I create and add those to a report?  I want to have one or many of the same page but with different data on each, saved to one pdf file.

Also, I really dont need to save the pdf file to disc, I just need to open it in a pdf viewer so the user can print.  Is there a way to just open the file without saving it?  


Author Comment

ID: 17075763
Another thing,

I did not understood your explanation of grouping.  How does it work and how do I use it?  Can you give me an example?
LVL 16

Expert Comment

ID: 17151019
Sorry for the late reply because I was on vacation last week.

Grouping is a basic function in all reporting tools (including Crystal report) and you can find many tutorials on that.  Here is one I found from internet.  http://www.crystaldevelopersjournal.com/artman/publish/article_118.shtml

In your case, you can link all your tables (address, customer, order) and pass to the report and then group by OrderID.  Then put data such as customer name, order number, order date, etc in the group header.  The item ordered and qty can be put in the details section.

Hope that helps

Author Comment

ID: 17154011
I finally got it to work, I did the following:

I created 2 crystal reports.
1 - Detail report linking to the datatable containing the detail records for the packing slip.
2 - A main report linking to the datatable with the header information.  I included the detail report as a subreport.

- Grouped the main report by order number so that there would be one page per order.
- Did not use the group headers at all, in fact suppressed them from displaying.  
- Placed the header info in the page header.
- Checked the "New Page After" option for the group footer in the section expert window so that  a new page was generated for each order
- Created a subreport link linking the order number of the detail items to the main page order number so only the details for that order would be generated on that page.

Accessing the report in my vb.net code:
- Added the crystal reports references.
- Included the following imports in my code
  Imports CrystalDecisions.CrystalReports.Engine
  Imports CrystalDecisions.Shared
- Open doc in the code:
   Dim cr As New ReportDocument
   cr.Load(Server.MapPath(FileRptName), OpenReportMethod.OpenReportByTempCopy)
- Set data for the report:
   Dim crSub As ReportDocument
   crSub = cr.OpenSubreport(FileSubRptName)
- Open report without saving it:
    Dim crDFDO As New DiskFileDestinationOptions
    crDFDO.DiskFileName = Server.MapPath(FileTempSaveName)
    With cr.ExportOptions
           .DestinationOptions = crDFDO
           .ExportDestinationType = ExportDestinationType.DiskFile
           .ExportFormatType = ExportFormatType.PortableDocFormat
     End With
     Response.ContentType = "application/pdf"

Accepted Solution

ee_ai_construct earned 0 total points
ID: 17356285
PAQ / No Refund
ee ai construct, community support moderator

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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