question

KerryOu-8610 avatar image
0 Votes"
KerryOu-8610 asked SeanFang-MSFT commented

How to preview a local RDLC report on web from reportviewer?

VS 2019
SQL2014 local server
VB code



I want to use reportviewer to show a RDLC report on web page, but I don't know how to set up. Any example for this?

Outstanding.rdlc is main report , Planinfo.rdlc & PLinfo.rdlc & Return.rdlc are sub report.
parameter: "Order"

How to put at the datasource in to the reportviewer an show this Outstanding.rdlc report?
It's my first time build a report on web from. Examples will make it easier for me to understand.

Thank you so much.

57454-1.jpg



my page code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

 <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    
 <%@ Register assembly="Microsoft.ReportViewer.WebForms" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
     <title></title>
 </head>
 <body>
     <form id="form1" runat="server">
     <div>
         <asp:ScriptManager ID="ScriptManager1" runat="server">
         </asp:ScriptManager>
         <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" BackColor="" ClientIDMode="AutoID" HighlightBackgroundColor="" InternalBorderColor="204, 204, 204" InternalBorderStyle="Solid" InternalBorderWidth="1px" LinkActiveColor="" LinkActiveHoverColor="" LinkDisabledColor="" PrimaryButtonBackgroundColor="" PrimaryButtonForegroundColor="" PrimaryButtonHoverBackgroundColor="" PrimaryButtonHoverForegroundColor="" SecondaryButtonBackgroundColor="" SecondaryButtonForegroundColor="" SecondaryButtonHoverBackgroundColor="" SecondaryButtonHoverForegroundColor="" SplitterBackColor="" ToolbarDividerColor="" ToolbarForegroundColor="" ToolbarForegroundDisabledColor="" ToolbarHoverBackgroundColor="" ToolbarHoverForegroundColor="" ToolBarItemBorderColor="" ToolBarItemBorderStyle="Solid" ToolBarItemBorderWidth="1px" ToolBarItemHoverBackColor="" ToolBarItemPressedBorderColor="51, 102, 153" ToolBarItemPressedBorderStyle="Solid" ToolBarItemPressedBorderWidth="1px" ToolBarItemPressedHoverBackColor="153, 187, 226" Width="1597px">
             <LocalReport ReportPath="Outstanding.rdlc">
             </LocalReport>
         </rsweb:ReportViewer>
        
         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="OutstandingTableAdapters.V___Order_OutstandingTableAdapter" OldValuesParameterFormatString="original_{0}">
             <SelectParameters>
                 <asp:FormParameter FormField="TextBox1" Name="Order" Type="String" />
             </SelectParameters>
         </asp:ObjectDataSource>
        
         <asp:SqlDataSource ID="SQLDataSourceS06" runat="server" ConnectionString="<%$ ConnectionStrings:S06ConnectionString %>" SelectCommand="SELECT * FROM [V - Order Outstanding] WHERE ([Order] = @Order)">
             <SelectParameters>
                 <asp:FormParameter FormField="TextBox1" Name="Order" />
             </SelectParameters>
         </asp:SqlDataSource>
         <br />
         <asp:TextBox ID="TextBox1" runat="server" Text="A2012449A"></asp:TextBox>
        
     </div>
     </form>
 </body>
 </html>

sql-server-reporting-servicesdotnet-aspnet-webforms
1.jpg (61.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SeanFang-MSFT avatar image
0 Votes"
SeanFang-MSFT answered SeanFang-MSFT commented

Hi @KerryOu-8610 ,

The common steps for adding RDLC report in webforms are:

  1. Prepare Typed DataSet => .xsd file in webforms

  2. Add RDLC Report with DataSet => .rdlc file in webforms

  3. Add ReportViewer and change the mode to local and attach it with the .rdlc file path

  4. Populate the RDLC Report from Database

It seems like you have completed the previous 3 steps. Do you want to know how to populate the data?

Your codes contain two DataSource controls, a) ObjectDataSource b) SqlDataSource. I don't think you need both to bind the data. You could refer to below demo using mock data from my side:

  • User (UserId, Name, Country) where UserId is the key and will be used to fetch data

  • TextBox will automatically trigger a postback if the text is changed and refresh the ReportView content

  • Set 'ProcessingMode' to 'Local' (necessary) and Set up a <Datasource> for <LocalReport>


ASPX:

  <form id="form1" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
         <div>
             <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Local" Font-Names="Verdana" Font-Size="8pt" BackColor="" ClientIDMode="AutoID" HighlightBackgroundColor="" InternalBorderColor="204, 204, 204" InternalBorderStyle="Solid" InternalBorderWidth="1px" LinkActiveColor="" LinkActiveHoverColor="" LinkDisabledColor="" PrimaryButtonBackgroundColor="" PrimaryButtonForegroundColor="" PrimaryButtonHoverBackgroundColor="" PrimaryButtonHoverForegroundColor="" SecondaryButtonBackgroundColor="" SecondaryButtonForegroundColor="" SecondaryButtonHoverBackgroundColor="" SecondaryButtonHoverForegroundColor="" SplitterBackColor="" ToolbarDividerColor="" ToolbarForegroundColor="" ToolbarForegroundDisabledColor="" ToolbarHoverBackgroundColor="" ToolbarHoverForegroundColor="" ToolBarItemBorderColor="" ToolBarItemBorderStyle="Solid" ToolBarItemBorderWidth="1px" ToolBarItemHoverBackColor="" ToolBarItemPressedBorderColor="51, 102, 153" ToolBarItemPressedBorderStyle="Solid" ToolBarItemPressedBorderWidth="1px" ToolBarItemPressedHoverBackColor="153, 187, 226" Width="1597px">
                 <LocalReport ReportPath="Outstanding.rdlc">
                     <DataSources>
                         <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                     </DataSources>
                 </LocalReport>
                    
             </rsweb:ReportViewer>
         </div>
         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"  OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="RDLCVB.OutstandingTableAdapters.UsersTableAdapter">
               
             <SelectParameters>
                 <asp:FormParameter DefaultValue="1" FormField="TextBox1" Name="userId" Type="Int32" />
             </SelectParameters>
                
         </asp:ObjectDataSource>
    
          <br />
          <asp:TextBox ID="TextBox1" runat="server" Text="1" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
     </form>

Code behind:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
     End Sub
    
     Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
         ReportViewer1.LocalReport.Refresh()
     End Sub


Other files in demo: Outstanding.xsd as a Typed DataSet, Outstanding.rdlc as a report component

Result:
QHlKz.gif


By the way, you could check the C# version and use C# - VB converter to converter the codes since rarely can you see the VB version example for report viewer

Hope this helps.
Best regards,
Sean



If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi SeanFang-MSFT ,
Thank you for your answer.
I try you way to set up in my web page , but It's still no working, showing "A data source instance has not been supplied for the data source 'outstanding'."
I'm still a little confused. How to set the sub report datasource? No need?
I choose the data sources in report viewer, but it is empty. What I did worng?
58353-2.jpg
58448-3.jpg

Please help, thank you so much.


0 Votes 0 ·

Hi @KerryOu-8610 ,

That is a bit weird. Have you tried to clearn and rebuild the project?
If you already attached the data source to the report, it should be detected in the designer.

What I can suggest is to recreate a new report using report wizard and configure the data source and data set for the report.
I think it might be a VS issue.

Best regards,
Sean


0 Votes 0 ·