C# 将参数传递给ReportView

C# 将参数传递给ReportView,c#,asp.net,reporting-services,parameters,C#,Asp.net,Reporting Services,Parameters,我有以下代码: protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e) { string strConnectionString = ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString; string strCustomerID = CommonCode.

我有以下代码:

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)传递到报表本身时,我有点不知所措。由于由于我编写了一段代码,strustomerid会自动填充客户的ID,因此如果我可以将strustomerid作为报告的参数传递给用户就太好了,这样用户就不必手动输入自己的ID

有人有什么建议吗?谢谢您的帮助。

您可以使用:


非常感谢。我不知道为什么,但是当我昨天尝试这个的时候,它出现了很多错误,尽管你引用的代码工作得很好。
ReportParameter p = new ReportParameter("CustomerID", strCustomerID);

this.reportViewer1.ServerReport.SetParameters(new ReportParameter[] { p });