我有以下代码:
protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e)
{
string strConnectionString = ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString;
string strCustomerID = CommonCode.GetCurrentCustomerID();
string strUserID = CommonCode.GetCurrentUserID().ToString();
DropDownList ddl = sender as DropDownList;
string strRSReportLinkID = ddl.SelectedValue;
using (SqlConnection connection = new SqlConnection(strConnectionString))
{
connection.Open();
SqlCommand command = new SqlCommand("Test_GetReportSettingsForReport", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@CustomerID", strCustomerID);
command.Parameters.AddWithValue("@UserId", strUserID);
command.Parameters.AddWithValue("@RSReportLinkID", strRSReportLinkID);
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string strURL = reader.GetValue(3).ToString();
GetReportPath(strURL);
}
}
else
{
/* Console.WriteLine("No rows found.");*/
}
reader.Close();
connection.Close();
}
}
protected void GetReportPath(string strURL)
{
this.ReportViewer1.ServerReport.ReportPath = "/" + strURL;
}
很简单,每次从我的下拉列表中选择报告时,都会运行ddlCompanyList_SelectedIndexChanged,它只使用存储过程来查找从下拉列表中选择的报告的URL。然后将其传递到GetReportPath,它将报告URL传递给ReportView。
到目前为止,一切正常,但我决定在我的SSRS报告中添加CustomerID作为参数。将参数传递到存储过程很容易,但是在将参数(CustomerID)传递到报表本身时,我有点迷失。由于我编写的代码,strCustomerID会自动填充客户的ID,如果我只能将strCustomerID作为报告的参数传递,那么用户就不必手动输入自己的ID。
有人有什么建议吗?谢谢你的帮助。
答案 0 :(得分:4)
您可以使用ServerReport.SetParameters:
ReportParameter p = new ReportParameter("CustomerID", strCustomerID);
this.reportViewer1.ServerReport.SetParameters(new ReportParameter[] { p });