-2
我有以下代碼:將參數傳遞給ReportView
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將運行時間,這只是使用一個存儲過程來找到該報告的網址從下拉菜單中選擇。然後這將傳遞到GetReportPath,它將報告URL傳遞到ReportView。
到目前爲止一切正常,但是我決定在我的SSRS報告中添加CustomerID作爲參數。將參數傳遞到存儲過程很容易,但是在將參數(CustomerID)傳遞給報表本身時,我有點遺憾。由於strCustomerID自動填充了客戶的ID,這要歸功於我編寫的代碼,如果我只需將strCustomerID作爲參數傳遞給我的報告,那就太好了,這樣用戶就不必手動輸入自己的ID。
任何人有什麼建議?謝謝您的幫助。
謝謝!我不知道爲什麼,但是當我昨天嘗試這個時,它錯誤很多,儘管你引用的代碼工作正常。 – JimmyK