我写了一个简单的webForm,其中包含1个文本框和一个ReportViewer(由Reoprt Wizard创建)。我在尝试执行报告时没有收到任何错误,但报告从未停止加载。我已经仔细检查了.rdlc文件(通过预览.xsd文件,它显示了预期的数据。所以,我在我的代码后面设置了一个断点,看看我是否可以识别问题。不知何故,代码成功完成,刷新ReportViewer代码,然后进入Designer.vb文件运行4个函数,然后再回到ReportViewer代码。我不明白Designer.vb代码中发生了什么。有人可以帮我理解一下我做错了?我将包含ASP.net,vb代码以及Designer.vb文件中的4个代码块。
ASP.net代码:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/HRMaster.Master" CodeBehind="VacationSick_EmployeeReportByArea.aspx.vb" Inherits="CEI_PerformanceReviews.VacationSick_EmployeeReportByArea" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HRPlaceHolder" runat="server">
<asp:Label ID="Label2" runat="server" style="z-index: 1; left: 74px; top: 215px; position: absolute" Text="Year:"></asp:Label>
<p>
</p>
<asp:DropDownList ID="ddl_Year" runat="server" DataSourceID="YearChooser" DataTextField="PeriodYYYY" DataValueField="PeriodYYYY" style="z-index: 1; left: 129px; top: 214px; position: absolute">
</asp:DropDownList>
<asp:SqlDataSource ID="YearChooser" runat="server" ConnectionString="<%$ ConnectionStrings:CafeWorksConnectionString %>" SelectCommand="SELECT DISTINCT PeriodYYYY
FROM Ted.CafeWorks.dbo.FatzPeriodDates
WHERE PeriodYYYY >= (DATEPART(YEAR, GetDate())-2)
ORDER BY PeriodYYYY DESC"></asp:SqlDataSource>
<asp:Button ID="btn_Refresh" runat="server" style="z-index: 1; left: 269px; top: 212px; position: absolute" Text="Refresh" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="XX-Large" ForeColor="#000099" style="z-index: 1; left: 0px; top: 142px; position: absolute; width: 1179px; text-align: center" Text="Employee Vacation/Sick Days by Area Report"></asp:Label>
<rsweb:ReportViewer ID="rv_EmployeeReportByArea" runat="server" Font-Names="Verdana" Font-Size="8pt" style="z-index: 1; left: 29px; top: 280px; position: absolute; height: 400px; width: 710px" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
<LocalReport ReportEmbeddedResource="CEI_PerformanceReviews.VacationSick_ReportByArea.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="Dilbert_VacationSickByArea" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetData" TypeName="CEI_PerformanceReviews.Dilbert_VacationSickByAreaTableAdapters.VacationSick_CalculationsByAreaProcTableAdapter" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_Year" DefaultValue="2014" Name="Year" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="CEI_PerformanceReviews.Dilbert_VacationSickByAreaTableAdapters.VacationSick_CalculationsByAreaProcTableAdapter" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_Year" Name="Year" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:Content>
VB代码背后:
Imports Microsoft.Reporting.WebForms
Public Class VacationSick_EmployeeReportByArea
Inherits System.Web.UI.Page
'Declare Variables
Dim Choose_Year As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Default the Year in ddl to this year
If (Page.IsPostBack) = False Then
ddl_Year.SelectedValue = Now.Year
End If
'When the page loads, fill the report with the current year's data
Choose_Year = ddl_Year.SelectedValue.ToString()
rv_EmployeeReportByArea.LocalReport.ReportPath = "VacationSick\VacationSick_ReportByArea.rdlc"
Dim Param As New ReportParameter("Year", "2014")
rv_EmployeeReportByArea.LocalReport.SetParameters({Param})
rv_EmployeeReportByArea.ServerReport.Refresh()
End Sub
执行文件Dilbert_VacationSickByArea.Designer.vb中的这4个代码块,然后返回到ReportViewer的PageLoad代码:
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property ClearBeforeFill() As Boolean
Get
Return Me._clearBeforeFill
End Get
Set
Me._clearBeforeFill = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected ReadOnly Property CommandCollection() As Global.System.Data.SqlClient.SqlCommand()
Get
If (Me._commandCollection Is Nothing) Then
Me.InitCommandCollection
End If
Return Me._commandCollection
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
答案 0 :(得分:1)
尝试仅打印报告If Not Me.Page.IsPostBack
。
您也可以删除rv_EmployeeReportByArea.ServerReport.Refresh()
,因为您正在使用LocalReport
。