How to use the selection formula in crystal report with ASP.NET

No.of Views6657
Bookmarked0 times
Downloads 
Votes0
By  youngmurukan   On  15 Feb 2010 21:02:15
Tag : Crystal Reports , How to
How to use the selection formula in crystal report with ASP.NET
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Abstract:

The purpose of this article will explore how to use the selection formula field to the user selection condition or values from the GUI with the ASP.NET. For example user needs to select a department to generate the report to view information only in that particular department. There are two ways to do this. First is use the parameter, second ways use the selection formula field in report document. We can call this filter data to generate report.

Technologies:

Crystal Report and ASP.NET

Language:

C# and VB.NET

Prerequisite:

Visual Studio 2005/2008 and Crystal report.

Implementation

In my previous article (Creating report with multi tables' information in ASP.NET) I have written how to generate crystal report with multiple tables. In that article we took a paid salary details report, for all department in the company. Here I am going to show you the same report for a particular department that user's selection. to read my previous article just click below.

Creating Crystal Report with Multiple Tables in ASP.NET

Follow the same steps and create the report. Use web project name as 'SelectionFormulaReportinASP' and report name 'SelectionFormulaReprot'.

Your report will be like this.

Now you need to add crystal report viewer and a button on the ASP.NET Webpage. Let us see, how we can add the report viewer on the page, just look at these html tags.

Html Code:

{codecitation class="brush: c#; gutter: true;" width="700px"}

style="height: 164px; margin-bottom: 151px">

onclick="btnLoad_Click" />

{/codecitation}

Create a table in form object. Then add a html row and a column.Then place the crystalReportViewer to the column as shown above html tag.If we complie this application, it will give a complier error "CR doesn't exist" when you haven't register Crystal report Namespace. Therefore, you need to register crystal report namespace on the top of the page as shown below.

{codecitation class="brush: c#; gutter: true;" width="700px"}

{/codecitation}

Note: when you double click on toolbox in the crystalreportviewer Visual studio will do all registeration and etc.

Now write few lines to display report on the viewer.

{codecitation class="brush: c#; gutter: true;" width="700px"}

protected void btnLoad_Click(object sender, EventArgs e)

{

// attached our report to viewer and set database login.

ReportDocument report = new ReportDocument();

report.Load(Server.MapPath("SelectionFormulaReprot.rpt"));

report.SetDatabaseLogon("username", " pwd",@"server", " database");

rptviewer.SelectionFormula ="{Department.Department} = '" +

txtDepartment.Text + "'";

rptviewer.ReportSource = report;

}

{/codecitation}

Note:When you give selection formula to report viewer you need take care of followings

1.you must use the single equal size , when you are check you're your data is equal

2.You always {Table.CoulmnName } syntax

3.when you check char values make sure you have to put values within the ' ' mark.

Here I have writen code under the btnLoad_Click event. On my code just create a report document object and load report from the path. MapPath() method to get absolute path from the report file name.

Then build the web application and run, you will get result like follow.

Conclusion:

This article is focused about creating report with selection formula. I hope this article helpful to you.

 
Sign Up to vote for this article
 
About Author
 
youngmurukan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 May 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
By:JohnBangoDate Of Posted:9/19/2011 7:27:14 AM
Re: Formula field in Crystal Report
Hi Author, Great article !!!!!!! quite entertained... please check out the following links for more details on formula field in crystal report ......... http://mindstick.com/Articles/ad1bda11-7a4c-4760-9df3-987f46b99029/?Formula%20Field%20in%20Crystal%20Report Thanks !!!!!
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top
</