Introduction:
In this article I will explain how to pass parameters to crystal reports using asp.net.
In this article I will explain how to pass parameters to crystal reports using asp.net.
Description:
In Previous post I explained clearly about how to create crystal report using asp.net. Now I will explain how to load crystal reports based on parameters using asp.net. This post is continuation of previous post Create crystal report using asp.net. if you didn’t read previous post crystal reports please check that one then come to this one because I am continuing from previous post in that I explained clearly to create the database tables and bind the reports and display it on page.
In Previous post I explained clearly about how to create crystal report using asp.net. Now I will explain how to load crystal reports based on parameters using asp.net. This post is continuation of previous post Create crystal report using asp.net. if you didn’t read previous post crystal reports please check that one then come to this one because I am continuing from previous post in that I explained clearly to create the database tables and bind the reports and display it on page.
Now Open Default.aspx page and add one textbox, button in your aspx page because by entering username in textbox we will search for the records for that we need to add textbox and button control on top of report by using below code
<div> Enter UserName: <asp:TextBox ID="txtUserName" runat="server"/> <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" /> </div> |
After add Textbox and button above the report design will be like this
Now Open MySampleDBDataSet.xsd file in that select Fill data and right click on it and select Configure
Now one window will that contains select query like this
Now our requirement is to pass the parameter and get the values based on that parameter for that we need to modify the query
SELECT UserId, UserName, FirstName, LastName, Location FROM UserInformation |
To
SELECT UserId, UserName, FirstName, LastName, Location FROM UserInformation WHERE (UserName LIKE '%' + @Name + '%') |
After modify our query select query window will like this
After enter the query click Next and Next and click Finish. Now open our Default.aspx page in design mode and select objectdatasource and click on smart tag in right side and click on Configure Data Source
After click on Configure Data Source one window will open in that select TableAdapter and click Next
After click on Next button now we will see available Data Methods in select Tab select GetData Method and click Next
After click Next button Define Parameters window will open in that we need to specify parameters for GetMethod. In this window First select ControlName in Parameters box after that Parameters Source and ControlID Options will enable now select Control in Parameter Source dropdown and select your textbox controlID in ControlID dropdown that would be like below figure.
After fill all options click Finish button we completed set everything to send parameters now open Default.aspx page and double click on your Submit button and write the following code in codebehind
protected void btnSubmit_Click(object sender, EventArgs e) { ReportViewer1.LocalReport.Refresh(); } |
Now build and run your application and check the output initially it won’t display any data once we type username in textbox and click on Submit button it will display the resultant data.
Demo
Please give your comments regarding above topic is it ok or not and if you like the post please share it.
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
21 comments :
thanks ...
Great post. Thanks!
Nice post sir..
I want to display full details of customer purchased. After displaying details when i will click on particular row, want to display another report with full customer purchased details.
Please help me sir..
Thank you...
I'm using the code below to pass the value of a textbox from an ASP Page into a rdlc report but the report is loading non stop and there's no error showing, please help
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WinForms;
using Microsoft.Reporting.WebForms;
using System.Data.SqlClient;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//assigning textboxes to the session variables from the search page
this.TextBox1.Text = (string)( Session["Date_From"]) ;
this.TextBox2.Text = (string)( Session["Date_To"]);
this.ReportViewer1.LocalReport.ReportEmbeddedResource = "My_First_Solution.My_Report.rdlc";
ReportParameter rp = new ReportParameter("DateFrom", this.TextBox1.Text,false );
ReportParameter rp2 = new ReportParameter("DateTo", this.TextBox2.Text,false );
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp, rp2 });
this.ReportViewer1.LocalReport.Refresh();
}
}
i have data in session field. How can i print it through crystal report. Can Anyone give me solution. It needs me because i want to print user details. I want to show user name first and then details. So i want to show user name from session then details from database.
Hi Suresh I am regular viewer to ur site.
This site helps me a lot
Thanks bro
Thanks you so much for step-by-step explanation.
how to pass parameter to cross tab crystal report inoredr to set column header as year. The year range is taken as input parameter.
good i gained lot ...
Good post......
Hi Suresh, thanks for the post.
I was trying to implement the solution. I am getting a error. When I first open the report, I see the error below the text box
"An error has occurred during report processing.
Exception has been thrown by the target of an invocation.Value cannot be null. Parameter name: CompName".
When I enter anything in the text box then only I get the report correctly. I want that initially it should open with all records.
hey suresh you are superb!! i have learned a lot from your website/
An error has occurred during report processing.
Cannot create a data reader for dataset 'DataSet1'.
What does this error means..??
Thanks! A lot you help me very much!
It is simple,sober and excellent.
Hello Suresh
I want make a report by report viewer.But Report Viewer Not Drag From Toolbox to .Aspx page. what is the prblm please tell me..Why report viewer not Drag from toolbox and drop to .aspx page.
An error occurred during print dialong
"Operation is not valid due to the current state of the object."
reportViewer1.PrintDialog();
Sir,I have one requirement regarding crystal report,how to generate report when the SQL query is passed from the text box,it should generate the report based on the query.
help me please
Thank You
hi suresh
i am facing problem in crystal reporting in web application , i want to know about HTML reporting please post a example on this.
thanks
Hello Sir,
I have performed similar steps , I am using dropdownbox control. But the data is not displaying in report.
Please guide me.
Thanks in advance
http://www.aspdotnet-suresh.com/2011/11/how-to-pass-parameters-to-crystal.html
After click on Next button now we will see available Data Methods in select Tab select GetData Method and click Next but in my website next button is disable so i am not able to click on Next
Note: Only a member of this blog may post a comment.