Thursday, April 15, 2010

How to pass set Crystal Report Parameter value from c# in runtime

Please visit my new Web Site

When you design a crystal report most of the time you need to use crstal report parameter specially to design report header. Like you are going to ouptut a report which contains a ceratin date data or may date range data. SO that you need to write the date range or date to specify the report data date. In this scenario you need to use Crystal report parameter because the data you will bind, may or may not contain the date or date range. User select a date or date range from front end & you will filter those data to bind the report as well as you need to set the date or date range value to report header by sending the date or date range to crystal report parameter. Here i will show you only how you can set one or more or multiple crystal report parameter from C# page in the runtime.

To know how to bind data please read the below url:
Runtime dynamically bind data into a crystal report using C#

Please follow the steps below:
1. Add a crystal report in your project.
2. From Field Explorer right click on Prameter Fields node & click on New.
Create parameter
3. Define the parameter name & Datatype.
Define parameter
4. Drag & Drop the parameter into your report
Drag Drop parameter
5. Now Add an aspx page into your project & set the datasource & parameter value in the following way:
protected void Button1_Click(object sender, EventArgs e)
        DataTable dt = new DataTable();


        DataRow oItem = dt.NewRow();
        oItem[0] = "Shawpnendu Bikash Maloroy";
        oItem[1] = "";
        oItem[2] = "+8801711080648";


        ReportDocument _rdTransactionDetails=new ReportDocument();
        string reportPath = Server.MapPath("rptusers.rpt");
 // Set the parameter value from here
 _rdTransactionDetails.SetParameterValue("date", DateTime.Now);
        CrystalReportViewer1.ReportSource = _rdTransactionDetails;

Please note that "set the parameter value into the report after binding data". Otherwise you will get a prompt to enter data.

Now run the project & check that the report shows the date that you send from aspx page in runtime:
Crystal Report


Purohit D said...

.net is one of the most user friendly software development platforms. development gives the way to develop complex web applications and web pages. Even most of the Business Intelligence software are being made on .net platforms with integrating as an essential functional part.

Anonymous said...

Excellent for me,Thanks!

Anonymous said...


KK said...

Awesome!! Finally got the result with your help

Want to say something?

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash