Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
I added report viewer to user control and used it in a page. i passed data table to report viewer but report viewer can't be displayed.

this is my ascx code

ASP.NET
<table align="center">
        <tr>
            <td>
                <asp:LinkButton runat="server" ID ="lbtnShowInstalledPrinters" Text ="Show Installed Printers" OnClientClick="showInstalledPrinters()"></asp:LinkButton>
                <%--<input type="button" id="btnShowInstalledPrinters" value="Show Insalled Printers"
                     önclick="showInstalledPrinters()" />--%>
            </td>
        </tr>
        <tr>
            <td align="center">
                <rsweb:ReportViewer ID="rvReport"  runat="server" Font-Names="Verdana" Font-Size="8pt"
                    Height="100%"  ShowRefreshButton="False" AsyncRendering ="False"
                    SizeToReportContent="True" Visible="True" Width="100%" ZoomMode="PageWidth">
                </rsweb:ReportViewer>
            </td>
        </tr>
    </table>


C#
and this is my ascx.cs code
 #region Properties

        public DataTable MainDataSource
        {
            set
            {
                ViewState["MainDataSource"] = value;

                rvReport.Reset();
                rvReport.LocalReport.DataSources.Clear();
                rvReport.LocalReport.DataSources.Add(new ReportDataSource("Main", value));
            }
            get
            {
                if (ViewState["MainDataSource"] != null)
                {
                    return (DataTable) ViewState["MainDataSource"];
                }
                return null;
            }
        }

        public DataTable HeaderDataSource
        {
            set
            {
                ViewState["HeaderDataSource"] = value;

            }
            get
            {
                if (ViewState["HeaderDataSource"] != null)
                {
                    return (DataTable)ViewState["HeaderDataSource"];
                }
                return null;
            }
        }
        
        public bool ShowInstalledPrinterBtn
        {
            set { lbtnShowInstalledPrinters.Visible = value; }
            get { return lbtnShowInstalledPrinters.Visible; }
        }

        public string rprtEmbeddedResource
        {
            set { ViewState["rprtEmbeddedResource"] = value; }
            get
            {
                if (ViewState["rprtEmbeddedResource"] != null)
                {
                    return ViewState["rprtEmbeddedResource"].ToString();
                }
                return null;
            }
        }

        #endregion Properties

        #region Page Events
   
        protected void Page_Load(object sender, EventArgs e)
        {
            rvReport.LocalReport.ReportPath = Server.MapPath("Reports/FUDSTDTranscriptRPT.rdlc");
            
        }

        #endregion Page Events

        #region Methods

        public void RefreshReport()
        {
            rvReport.Reset();
            rvReport.LocalReport.DataSources.Clear();
            rvReport.LocalReport.ReportPath =  Server.MapPath("Reports/FUDSTDTranscriptRPT.rdlc");
            rvReport.LocalReport.DataSources.Add(new ReportDataSource("Main", MainDataSource));
            rvReport.LocalReport.DataSources.Add(new ReportDataSource("HeaderDS", HeaderDataSource));
            rvReport.Visible = (MainDataSource.Rows.Count != 0 && HeaderDataSource.Rows.Count!=0);
            rvReport.LocalReport.ReportEmbeddedResource = rprtEmbeddedResource;
            rvReport.LocalReport.Refresh();
        }

        public void DisableUnwantedExportFormat(ReportViewer ReportViewerID, string strFormatName)
        {
            FieldInfo info;

            foreach (RenderingExtension extension in ReportViewerID.LocalReport.ListRenderingExtensions())
            {
                if (extension.Name == strFormatName)
                {
                    info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    info.SetValue(extension, false);
                }
            }
        }

        #endregion Methods
    }
}
Posted
Comments
Kishore Pogaru 18-Sep-14 9:13am    
Are you getting any error? or you are not able to see the report?
shijuse 18-Sep-14 11:15am    
In the page directive set EnableEventValidation="fase" and try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900