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

Kerry Ou 226 Reputation points
2021-01-18T07:11:18.477+00:00

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>  
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,219 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,771 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sean Fang-MSFT 156 Reputation points
    2021-01-19T07:44:31.043+00:00

    Hi @Kerry Ou ,

    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.