簡體   English   中英

以編程方式控制SQL Server Reporting Services報表查看器

[英]Controlling the SQL Server Reporting Services Report Viewer programmatically

我對SSRS的ReportViewer控件的ASP.NET版本有問題。

在我的ASP.NET Web表單文件中,我有:

    <rsweb:ReportViewer ID="webViewer" runat="server" Width="100%" Height="100%" 
        ProcessingMode="Remote">
        <ServerReport ReportPath="/AnalyticReports/SiteOverview" 
            ReportServerUrl="http://someserver/ssrs" />
    </rsweb:ReportViewer>

這可以正常工作,如預期的那樣。

但是,我想要以編程方式更改服務器和報告路徑。 我該怎么辦?

我試過這個:

webViewer.ServerReport.ReportServerUrl = new Uri("http://someserver/ssrs");
webViewer.ServerReport.ReportPath = "/AnalyticReports/SiteOverview";
webViewer.ServerReport.Refresh();

然而,這似乎沒有做任何事情。 我甚至嘗試添加webViewer.Reset()但無濟於事。

有人指出我正確的方向嗎?

實際上,問題似乎在於Page_Load事件。 在遇到http://msdn.microsoft.com/en-us/library/aa337091.aspx后,我嘗試了Page_Init ,事情似乎按預期工作。

我這樣做是使用一個屬性來獲取和設置值

public string ReportPathString 
{ get { return ReportViewer1.ServerReport.ReportPath; } 
  set { ReportViewer1.ServerReport.ReportPath = value; } 
}

public string ReportServerUrlString 
{ get { return ReportViewer1.ServerReport.ReportServerUrl.ToString(); } 
  set { ReportViewer1.ServerReport.ReportServerUrl = new Uri(value); } 
}

同時在page_load,我使用以下代碼來設置憑據

IReportServerCredentials irsc = new ReportServerCredentials("Username", "Password", "Domain");

下面使用的類

public class ReportServerCredentials : IReportServerCredentials
{
private string _UserName;
private string _PassWord;
private string _DomainName;

public ReportServerCredentials(string UserName, string PassWord, string DomainName)
{
    _UserName = UserName;
    _PassWord = PassWord;
    _DomainName = DomainName;
}

public System.Security.Principal.WindowsIdentity ImpersonationUser
{
    // use default identity
    get { return null; }
}

public ICredentials NetworkCredentials
{
    // use default identity
    get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
}

public bool GetFormsCredentials(out Cookie authCookie, out string user,
 out string password, out string authority)
{
    authCookie = null;
    user = password = authority = null;
    return false;
}


}

編輯:剛看到這個話題已經有一年了......

你試過這個嗎,勞埃德?

webViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;

我使用LocalReport似乎工作得更好:

var reportDataSource = new ReportDataSource("DataSet1", resultSet);

ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/" + reportName + ".rdl");
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);

ReportViewer1.LocalReport.Refresh();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM