2013-12-09 48 views
0
protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!Page.IsPostBack) 
     { ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote; 
      ReportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://123.abc/Reportserver"); 
      ReportViewer1.ServerReport.ReportPath = "/Test/Development/Details"; 
      ReportViewer1.ShowParameterPrompts = true; 
      ReportViewer1.ShowPrintButton = true; 


      ReportParameter[] rptParams = new ReportParameter[1]; 
      SqlConnection MA = new SqlConnection(MedA); 
      SqlCommand command = new SqlCommand("select distinct Users from PROD.Users Where Username ='" + this.Username + "'", MA);   
      SqlDataAdapter dataAadpter = new SqlDataAdapter(command); 
      DataSet ds = new DataSet(); 
      dataAadpter.Fill(ds); 
      rptParams[0] = new ReportParameter("UserID", ds); //this.Username 
      ReportViewer1.ServerReport.SetParameters(rptParams); 
      ReportViewer1.ServerReport.Refresh(); 
      ReportViewer1.AsyncRendering = false; 
      ReportViewer1.SizeToReportContent = true; 
     } 

我無法傳遞參數。我試圖從登錄用戶獲取用戶密鑰。誰能幫我將參數存儲在報表查看器的變量中

+0

您的報表服務器安全性是如何配置的? Windows身份驗證或表單身份驗證。如果它是Windows認證爲什麼你需要傳遞給用戶?你正在跳到另一臺機器上嗎? – Daniel

+0

@Daniel我正在使用表單身份驗證。我有一個來自我的用戶名的登錄頁面。使用用戶名,我從DB獲取密鑰。 – Valley

回答

1

首先存儲的用戶名從你的登錄界面如下圖所示:

Session["LoggedInUser"] = txtUsername.Text.Trim(); 

然後粘貼到您的報告頁面下面的代碼:

protected String Username 
    { 
     get 
     { 
      return Convert.ToString(Session["LoggedInUser"]); 
     } 
    } 

在頁面加載寫如下的代碼爲您報告:

protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!Page.IsPostBack) 
      { ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote; 
       ReportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://123.abc/Reportserver"); 
       ReportViewer1.ServerReport.ReportPath = "/Test/Development/Details"; 
       ReportViewer1.ShowParameterPrompts = true; 
       ReportViewer1.ShowPrintButton = true; 

     ReportParameter[] rptParams = new ReportParameter[1]; 
     SqlConnection MA = new SqlConnection(MedA); 
     SqlCommand command = new SqlCommand("select distinct Users from PROD.Users Where Username ='" + this.Username + "'", MA);   
     SqlDataAdapter dataAadpter = new SqlDataAdapter(command); 
     DataSet ds = new DataSet(); 
     dataAadpter.Fill(ds); 
     rptParams[0] = new ReportParameter("UserID", ds.Tables[0].Rows[0][0].ToString()); //this.Username 
     ReportViewer1.ServerReport.SetParameters(rptParams); 
     ReportViewer1.ServerReport.Refresh(); 
     ReportViewer1.AsyncRendering = false; 
     ReportViewer1.SizeToReportContent = true; 
    }