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.
3.
Define the parameter name & Datatype.
4.
Drag & Drop the parameter into your report
5.
Now Add an aspx page into your project & set the datasource & parameter
value in the following way:
01 |
protected void Button1_Click( object sender,
EventArgs e) |
03 |
DataTable dt = new DataTable();
|
05 |
dt.Columns.Add( "username" );
|
06 |
dt.Columns.Add( "useremail" );
|
07 |
dt.Columns.Add( "mobile" );
|
09 |
DataRow oItem = dt.NewRow();
|
10 |
oItem[0] = "Shawpnendu
Bikash Maloroy" ;
|
11 |
oItem[1] = "shawpnendu@gmail.com" ;
|
12 |
oItem[2] = "+8801711080648" ;
|
16 |
ReportDocument _rdTransactionDetails= new ReportDocument();
|
17 |
string reportPath =
Server.MapPath( "rptusers.rpt" ); |
18 |
_rdTransactionDetails.Load(reportPath);
|
19 |
_rdTransactionDetails.SetDataSource(dt);
|
22 |
_rdTransactionDetails.SetParameterValue( "date" , DateTime.Now);
|
23 |
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:
Comments
Post a Comment