How to create parametrized reports using microsoft report viewer?
Put more details in your question, but as i understand the MSDN ReportViewer Controls will be very nice to you learn more by yourself.
Check out http://www.youtube.com/watch?v=sXJmRHgSAS8&feature=related
For one thing, I would avoid the Microsoft report viewer control. Just use a browser control, and browse to the report, passing in the parameters in the URL like you would when using a browser.
This is much better for many reasons.
The MS Report Viewer Control has a lot of bugs that you will be stuck with.
The browser and the report viewer render the reports differently (slightly) such as with margins etc. So you will have to tweak most of your reports if you ever switch to a web application and need to use the browser to access reports. This brings me to the next issue . . .
If you ever need to go to a web application, you will need to reimplement how you call reports, pass parameters, etc. instead of just using the browser functionality you already have created (you access the reports differently using the control vs. using a browser)
Otherwise, if you truly want to use the Report Viewer control, here is a sample (using .NET 2.0):
ReportViewer rvReportViewerControl = new ReportViewer();
rvReportViewerControl.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
rvReportViewerControl.ServerReport.ReportServerUrl = new Uri("http://<SERVERNAME>/ReportServer");
rvReportViewerControl.ServerReport.ReportPath = "<FOLDER PATH TO REPORTS>");
rvReportViewerControl.ShowParameterPrompts = false;
Microsoft.Reporting.WinForms.ReportParameterInfoCollection rpInfoCollection = rvReportViewerControl.ServerReport.GetParameters();
if (rpInfoCollection.Count > 0)
{
List<ReportParameter> paramList = new List<ReportParameter>();
foreach (ReportParameterInfo reportParameter in rpInfoCollection)
{
string parameterName = reportParameter.Name.ToString();
string parameterValue = "";
bool isParameterVisible = reportParameter.Visible;
paramList.Add(new ReportParameter(parameterName, parameterValue, isParameterVisible));
}
rvReportViewerControl.ServerReport.SetParameters(paramList);
}
rvReportViewerControl.RefreshReport();
This site has a lot of useful information.
Related
I get javascript errors when adding a report to an ASPX page. When clicking the view button I get javascript errors.
A simple report with a set of parameters throws the following javascript error. I'm using the local processing mode with a dynamically generated set of data sources and parameters. When I load the page without parameters, I see the following error.
And when I add the parameters, the following exceptions will show up.
This is the code to generate the report. The backend processing runs successfully, but when it comes to the client-side processing, it fails to display the report component.
ReportViewer1.Reset();
ReportViewer1.Visible = true;
ReportViewer1.EnableTelemetry = false;
ReportViewer1.ShowParameterPrompts = true;
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath($"~/Reports/{_reportName}");
foreach (var param in ReportParameters.Where(r => r.Hidden))
ReportViewer1.LocalReport.SetParameters(new ReportParameter(param.Name, param.DefaultValue));
foreach (var dataset in DataSets)
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource(dataset, GetReportData(dataset)));
ReportViewer1.LocalReport.Refresh();
Update:
I just noticed this issue only happens in Chrome. I've been able to open the report in IE successfully.
Apparently, this issue happens when a previous version of SSRS still cached in the IIS Express or IIS. A system restart resolved the issue.
I have 2 parameters (Detail, Summary) that I have created in a Crystal Report. The report is called from c# in a Windows Forms application. I am trying to pass the appropriate value to each parameter at runtime so the report can make some decisions based on the values. I have read many articles regarding this and I think I am using the best method to accomplish this?
This is the simple code I have implemented after the report has been loaded and before the SetDataSoruce has been set:
crReportDocument.SetParameterValue("DetailView", false);
crReportDocument.SetParameterValue("SummaryView", true);
For some reason the values are not getting to the report as the report is always prompting for the values to be set when it runs.
Everything else about the report works correctly.
I would appreciate any light someone can shed on this matter as it seems to be a simple task to do?
Actually the problem was code placement. I was populating the parameters in the wrong place of code execution:
This is how I had it when it was not working:
crReportDocument.SetParameterValue("FromDate", dtmFromDate);
ReportViewer reportViewer = new ReportViewer();
reportViewer.ReportSource = crReportDocument;
To resolve I moved the code around as follows:
ReportViewer reportViewer = new ReportViewer();
reportViewer.ReportSource = crReportDocument;
crReportDocument.SetParameterValue("FromDate", dtmFromDate);
That's all it took to get it to work correctly.
Let me know if it does not work for you.
The problem is that the parameter must be passed using format {?PARAMETER}.
It works.
crReportDocument.SetParameterValue("{?DetailView}", false);
crReportDocument.SetParameterValue("{?SummaryView}", true);
I am able to display the report on web browser.My problem is, when I use the toolbar(such as export button,print button,find button and so on) of crystal report I am facing the parameter missing error over web browser.Please help me how to shut out this issue in asp.net platform by using c#.
Thanks in Advance.
You need to store/persist your reportdocument object in session variables
if (!Page.IsPostBack)
{
rpt = new ReportDocument();
Session["report"] = rprt; // store the report in the Session
}
else
{
rpt = (ReportDocument)Session["report"];
}
and here is the explanation
http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2011/04/25/why-should-i-store-reports-object-in-httpsession
We would like to automate certain tasks in a website, like having a user 'login', perform some functionality, read their account history etc.
We have tried emulating this with normal POST/GETs, however the problem is that for example for 'login', the website uses javascript code to execute an AJAX call, and also generate some random tokens.
Is it possible to literally emulate a web-browser? For example:
Visit 'www.[test-website].com'
Fill in these DOM items
DOM item 'username' fill in with 'testuser'
DOM item 'password' fill in with 'testpass'
Click' button DOM item 'btnSubmit'
Visit account history
Read HTML (So we can parse information about each distinct history item)
...
The above could be translated into say the below sample code:
var browser = new Browser();
var pageHomepage = browser.Load("www.test-domain.com");
pageHomepage.DOM.GetField("username").SetValue("testUser");
pageHomepage.DOM.GetField("password").SetValue("testPass");
pageHomepage.DOM.GetField("btnSubmit").Click();
var pageAccountHistory = browser.Load("www.test-domain.com/account-history/");
var html = pageAccountHistory.GetHtml();
var historyItems = parseHistoryItems(html);
You could use for example Selenium in C#. There is a good tutorial: Data Driven Testing Using Selenium (webdriver) in C#.
I would suggest to instantiate a WebBrowser control in code and do all your work with this instance but never show it on any form. I've done this several times and it works pretty good. The only flaw is that it makes use of the Internet Explorer ;-)
Try JMeter, it is a nice too for automating web requests, also quite popularly used for performance testing of web sites
Or just try System.Windows.Forms.WebBrowser, for example:
this.webBrowser1.Navigate("http://games.powernet.com.ru/login");
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
System.Windows.Forms.Application.DoEvents();
HtmlDocument doc = webBrowser1.Document;
HtmlElement elem1 = doc.GetElementById("login");
elem1.Focus();
elem1.InnerText = "login";
HtmlElement elem2 = doc.GetElementById("pass");
elem2.Focus();
elem2.InnerText = "pass";
I've done a asp.net application to generate reports over a particular data. Initially i created local reports (.rdlc) to generate reports. I created separate .xsd for each rdlc and designed the reports. I build the dataset programmatically and bind it to the rdlc. I used the following code for binding the datasource to the reports -
rptMyReport.LocalReport.ReportPath = Server.MapPath(srdlcName);
rptMyReport.LocalReport.DataSources.Add(rds);
Now i have converted all the rdlc to rdl following this msdn article and i've published the reports to the report server.
rptMyReport.ServerReport.ReportServerUrl = new System.Uri("http://ReportServer/ReportServer");
rptMyReport.ServerReport.ReportPath = "/ReportFolder/ReportName";
Now how can i set the datasource to the reports programmatically?
This work is impossible. you should create your datasource in your rdl report. you must write needed queries for report data gathering. you can use this query as a text or stored procedure. You can pass parameters to this query and filter the output of the query.
you can only pass the parameters to rdl report like this:
ReportParameter[] Params = new ReportParameter[1];
Params[0] = "Parameter Value";
ReportViewerControl.ServerReport.SetParameters(Params);
What are you trying to do? I believe the datasource is mentioned within the .RDL file itself.
For ex: When you create an Report using BIDS, you can specify the datasource. This gets added to the .RDL file. The same concept holds true here as well.
This is not impossible, but may take a little effort if this is what you want to do.
You have a couple of options:
If you create a shared datasource on your report server you can add it manually using the RDLObjectModel. Get the shared datasource name and guid from your reportserver and you can add it to your report.
Example:
'create the datasource for the report
Dim dataSrcRFoo = New RdlObjectModel.DataSource
dataSrcRFoo.Name = "DataSourceName"
dataSrcRFoo.DataSourceReference = "/path/to/DataSource"
dataSrcRFoo.IsShared = True
dataSrcRFoo.SecurityType = 2 ' RdlObjectModel.SecurityTypeEnum.DataBase
dataSrcRFoo.DataSourceID = New Guid("shareddatasourceguid")
'add data source to report
rdlRpt.DataSources.Add(dataSrcRFoo)
Another option is to use templates on the server that have the share (or report level) datasource built in.