我新建一个报表Report1.rdl,定义了一个参数@s_dept,其SQL语句为"select * from user where dept=@s_dept",然后新建一项目,新建一窗体webfrom1.aspx,把ReportViewer控件拖进去,设置其ServerUrl属性为"http://dong/reportserver",ReportPath属性为"/report1"。像上面的设计时,在运行查看时,发现@s_dept这个变量就会现在在页面上,要求用户去录入,之后点击“查看报表”才能显示数据。可这不是我所要求的,我要实现的是:比如在一主窗体上有一“打印”按钮,点击它后,弹出上面的webfrom1.aspx,此时@s_dept的值是从该主窗体传入进去的,而不是像现在这样由用户去录入或选择,就是说不用显示出@s_dept这个变量的文本框,而是在webfrom1.aspx页面弹出时直接根据主窗体传入的值显示出数据。我想这代码应该写在webfrom1.aspx的Page_Load事件中,用Request来获得主窗体传入的@s_dept变量值,可如何传给ReportViewer控件,即让Report1.rdl得到这个值,从而抽取出数据来。
(注:一定在页面上不显示@s_dept变量的录入的文本框)请各位多帮忙,多来支持。

解决方案 »

  1.   

    二种访问方式,一种是用URL带参数直接访问.一种是用WEBSERVICES访问..
    建议你听一听在线讲座..
    http://www.mswebcast.com.cn/technet/recordItem.aspx?id=msft082604vx
      

  2.   

    请问第一种是用URL带参数直接访问,请楼上高手能不能给个实例或说详细点,Reporting Server入门不久,不是很明白的,请高手耐心指教,表示感谢了。已经转了好几次帖了,就是没人回答。
      

  3.   

    // ReportViewer1.ServerUrl = "http://sps.hnpc.com.cn/ReportServer";
    ReportViewer1.ReportPath = "/Sxfy/ReportFillCollect" ; ReportViewer1.SetQueryParameter("Year", this.DropDownList4.SelectedValue);//*********************************************
    添加服务控件一个方法......然后在cs中调用就行了.....
      

  4.   

    /// <summary>
       /// 接受Axps传递的参数
       /// </summary>
       /// <param name="name"></param>
       /// <param name="value"></param>
       public void SetQueryParameter(string name, string value)
       {
       this.SetParameter(name , value);
       }//*********************************
    添加后,重新生成,引用。。
    ReportViewer1.SetQueryParameter("Parameter1", 1);ReportViewer1.SetQueryParameter("Parameter2", 2);所传递参数不限...................
      

  5.   

    to : lutao206(海口冰玲) public void SetQueryParameter(string name, string value)
       {
       this.SetParameter(name , value);
       }这句话不能通过的,说“窗体不包含对SetParameter的定义”。我把它直接写在.cs文件中。
      

  6.   

    Reporting Server 的有一个服务器端控件,ReportViewer不知你是否安装了例子?
    ********************************** 看来你没有学习过自定义控件,加强这方面的知识吧。
    /*=====================================================================File:  Viewer.cs
    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing.Design;
    using System.Drawing;namespace Microsoft.Samples.ReportingServices
    {
       public class ReportViewer : WebControl
       {
         
          #region Methods
          /// <summary>
          /// Add or remove url access string properties. 
          /// </summary>
          /// <param name="name"></param>
          /// <param name="value"></param>
          private void SetParameter(string name, string value)
          {
             try
             {
                // Remove if value is null or empty. Value is null of the property grid value
                // is null or empty. Empty or null removes the property from the Hashtable.
                if(value == null | value == String.Empty )
                {
                   this._properties.Remove(name);
                }
                else
                {
                   if(this._properties.ContainsKey(name))
                   {
                      // Change if key exists
                      this._properties[name] = value;
                   }
                   else
                   {
                      // Add if key does not exist
                      this._properties.Add(name, value);
                   }
                }
                // Build a new url string
                this.BuildUrlString();
             }
                // Catch and handle a more specific exception in a propduction application.
             catch(Exception ex)
             {
                // Sample throws the exception to the client
                throw ex;
             }
          }
          
          /// <summary>
          /// Enumerate Hashtable and create report server access specific string.
          /// </summary>
          /// <param name="properties"></param>
          /// <returns></returns>
          private string EmumProperties(Hashtable properties)
          {
             string paramsString = String.Empty;
             // Enumerate properties and create report server specific string.
             IDictionaryEnumerator customPropEnumerator = properties.GetEnumerator();
             while ( customPropEnumerator.MoveNext() )
             {
                paramsString += "&" 
                   + customPropEnumerator.Key 
                   + "=" + customPropEnumerator.Value;
             }         return paramsString;
          }    /// <summary>
       /// 接受Axps传递的参数
       /// </summary>
       /// <param name="name"></param>
       /// <param name="value"></param>
       public void SetQueryParameter(string name, string value)
       {
       this.SetParameter(name , value);
       }
          
          /// <summary>
          /// Add URL access command for rendering a report and any
          /// additional parameters.
          /// </summary>
          public string BuildUrlString()
          {
             this._url = this._serverUrl + "?" + this._reportPath + 
                "&rs:Command=Render" + this.EmumProperties(this._properties);
             return this._url;
          }
          #endregion    }
    }
      

  7.   

    *****************************************************************ReportViewer.cs
    这是我在原例子添加了一个方法SetQueryParameter(),修改后请重新生成一次,再进行调用,否则一样找不到此方法:) , 请你细看,不明之处,可以继续留帖子。至少调用方法,你已基本理解:)
      

  8.   

    这里有你要想知道的东西
    http://www.cnblogs.com/zsww/archive/2004/06/02/12894.aspx?Pending=true#Post
      

  9.   

    感谢各位的支持,尤其是 drk928(一起看斜阳)、lutao206(海口冰玲) 、 dragonforfly(飘零)三位的帮助,将另开此http://community.csdn.net/Expert/topic/3605/3605091.xml?temp=.6861231贴给分。
      

  10.   

    请drk928(一起看斜阳)、lutao206(海口冰玲) 、 dragonforfly(飘零)三位到http://community.csdn.net/Expert/topic/3605/3605091.xml?temp=.6861231再次来领分。