In Designer page add RDLC Report viewer
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
Visible="false" Width="100%" OnPreRender="ReportViewer1_PreRender" InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Style="border: #c2c1be solid 1px;"></rsweb:ReportViewer>
Based on your requirement design Report
In button click place below code
ReportViewer1.Visible = true;
string reportPath = ConfigurationManager.AppSettings["ReportsPath"] + "ReportName.rdlc";
//Pass "Report name" and "Data Set" to Report Data source
ReportDataSource datasource = new ReportDataSource("ReportataSet",
CommisionOverView);
//Clear existing Report Data Source
ReportViewer1.LocalReport.DataSources.Clear();
//Add new Data Source
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);
//Pass Report file to Report Viewer
ReportViewer1.LocalReport.ReportPath =
Server.MapPath(reportPath);
//Display Report File Name
ReportViewer1.LocalReport.DisplayName = "ReportName" + Convert.ToDateTime(DateTime.Now).ToString("ddMMMyyyyhhmmss");
------------------------------Passing
Parameters to RDLC--------------------------
ReportParameter rp = new
ReportParameter("prmMonth", this.ddlMonth.SelectedItem.Text, false);
ReportParameter rp2 = new
ReportParameter("prmYear", this.ddlYear.SelectedItem.Text, false);
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp, rp2 });
ReportViewer1.LocalReport.Refresh();
#region Hiding XML,MHTML,CSV Document in a Report Viewer
protected void
ReportViewer1_PreRender(object sender, EventArgs e)
{
DisableUnwantedExportFormats(ReportViewer1.LocalReport);
}
public static void DisableUnwantedExportFormats(LocalReport
rvServer)
{
foreach (RenderingExtension extension in rvServer.ListRenderingExtensions())
{
//|| extension.Name == "WORD"
if (extension.Name == "XML"
|| extension.Name == "MHTML" ||
extension.Name == "CSV")
{
ReflectivelySetVisibilityFalse(extension);
}
}
}
public static void ReflectivelySetVisibilityFalse(RenderingExtension
extension)
{
FieldInfo info = extension.GetType().GetField("m_isVisible", BindingFlags.NonPublic
| BindingFlags.Instance);
if (info != null)
{
info.SetValue(extension, false);
}
}
#end region
No comments:
Post a Comment