-1

次のコードがあります。

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 が検索されます。これは、レポートの URL を ReportView に渡す GetReportPath に渡されます。

これまでのところすべて正常に動作していますが、SSRS のレポートに CustomerID をパラメーターとして追加することにしました。パラメータをストアド プロシージャに渡すのは簡単でしたが、レポート自体にパラメータ (CustomerID) を渡すときは少し戸惑いました。私が書いたコードのおかげで、strCustomerID には顧客の ID が自動的に入力されるので、ユーザーが自分の ID を手動で入力する必要がないように、レポートのパラメーターとして strCustomerID を渡すことができれば素晴らしいと思います。

ここに画像の説明を入力

誰にも提案はありますか?助けてくれてありがとう。

4

1 に答える 1

5

ServerReport.SetParametersを使用できます。

ReportParameter p = new ReportParameter("CustomerID", strCustomerID);

this.reportViewer1.ServerReport.SetParameters(new ReportParameter[] { p });
于 2013-10-09T14:34:33.710 に答える