Thursday, April 15, 2010

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




Please visit my new Web Site WWW.Codedisplay.com



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 asp.net 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 Asp.net 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();

        dt.Columns.Add("username");
        dt.Columns.Add("useremail");
        dt.Columns.Add("mobile");

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

        dt.Rows.Add(oItem);

        ReportDocument _rdTransactionDetails=new ReportDocument();
        string reportPath = Server.MapPath("rptusers.rpt");
        _rdTransactionDetails.Load(reportPath);
        _rdTransactionDetails.SetDataSource(dt);
        
 // 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

4 comments:

Purohit D said...

.net is one of the most user friendly software development platforms. ASP.net 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 ASP.net as an essential functional part.

Anonymous said...

Excellent for me,Thanks!

Anonymous said...

superb

KK said...

Awesome!! Finally got the result with your help

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • 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