将多个参数从Custom WebPart传递到Reporting Services Report Viewer webpart

时间:2010-04-01 22:59:24

标签: sharepoint reporting-services web-parts

我在Sharepoint模式下使用Reporting Services,我能够在Sql Server Reporting Services报表查看器中显示报表,报表有多个参数,我的问题是如何将多个参数从自定义Web部件传递到这份报告。

我可以通过在自定义webpart中实现ITransformableFilterValues接口来传递一个参数,我想要做的是传递多个参数。

例如:如果报告中有2个参数,那么我应该能够从webpart中的控件中映射每个参数。

2 个答案:

答案 0 :(得分:6)

以下是自定义Webpart代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using aspnetwebparts = System.Web.UI.WebControls.WebParts;
//using Microsoft.Office.Server.Utilities;
using wsswebparts = Microsoft.SharePoint.WebPartPages;
//using Microsoft.SharePoint.Portal.WebControls;
using System.Collections.ObjectModel;
using Microsoft.SharePoint.Utilities;
using System.Data;
using System.Collections;

namespace CustomWebPart
{
    /// <summary>
    /// Used to provide filter values for the status report.
    /// </summary>
    public class StatusReportFiler : aspnetwebparts.WebPart, wsswebparts.ITransformableFilterValues
    {
        DropDownList ddlCategory;
        ListItem lstItem;
        Label lblCaption; 

        public virtual bool AllowMultipleValues
        {
            get
            {
                return false;
            }
        }
        public virtual bool AllowAllValue
        {
            get
            {
                return true;
            }
        }

        public virtual bool AllowEmptyValue
        {
            get
            {
                return false;
            }
        }
        public virtual string ParameterName
        {
            get
            {
                return "Category";
            }
        }



        public virtual ReadOnlyCollection<string> ParameterValues
        {
            get
            {
                string[] values = this.GetCurrentlySelectedCategory();
                return values == null ?
                    null :
                    new ReadOnlyCollection<string>(values);
            }
        }


        protected override void CreateChildControls()
        {


            lblCaption = new Label();
            lblCaption.Text = "&nbsp; Category:&nbsp;";

            Controls.Add(lblCaption);

            ddlCategory = new DropDownList();
            ddlCategory.AutoPostBack = true;

            lstItem = new ListItem();
            lstItem.Text = "Select All Category";
            lstItem.Value = "0";
            ddlCategory.Items.Add(lstItem);
            lstItem = null;


            lstItem = new ListItem();
            lstItem.Text = "BING";
            lstItem.Value = "Bing";
            ddlCategory.Items.Add(lstItem);
            lstItem = null;

            lstItem = new ListItem();
            lstItem.Text = "Google";
            lstItem.Value = "Google";
            ddlCategory.Items.Add(lstItem);
            lstItem = null;


            Controls.Add(ddlCategory);



           // base.CreateChildControls();
        }


        [aspnetwebparts.ConnectionProvider("Category Filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
        public wsswebparts.ITransformableFilterValues SetConnectionInterface()
        {
            return this;
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
        }

        public string[] GetCurrentlySelectedCategory()
        {
            string[] selCategory = new string[1];
            selCategory[0] = ddlCategory.SelectedValue;
            return selCategory;
        }

        protected override void RenderContents(HtmlTextWriter htmlWriter)
        {


            /*htmlWriter.Write("<table border=\"0\" width=\"100%\">");
            htmlWriter.Write("<tr><td>");
            lblCaption.RenderControl(htmlWriter);
            htmlWriter.Write("</td></tr>");
            htmlWriter.Write("<tr><td>");
            lblCaption.RenderControl(htmlWriter);
            htmlWriter.Write("</td></tr>");
            htmlWriter.Write("</table>");*/

            this.EnsureChildControls();
            RenderChildren(htmlWriter);

        }

    }
}
  1. 构建此Webpart后,将其部署到SharePoint。 在Sharpoint中创建Webpart页面,将自定义Web部件添加到页面。 添加后,您将能够在Webpart上看到带有值的下拉列表。

  2. 在另一个添加Webpart部分中添加一个Sql Server报告服务ReportViewer Web部件并在属性部分中设置报告URL,然后单击“应用”,此报告应具有与“自定义Web部件”中相同的参数名称。

  3. 在自定义Web部件中,点击编辑 - &gt;连接 - &GT;发送类别过滤器到 - &gt; ReportViewer - AAAA(这是ReportName I Guess)。这将弹出一个带有映射部分的Window,将Filer Category to Filtered参数映射到Report上,然后单击Finish。这会将Webpart中的值传递给Report。

  4. 希望这有帮助。

答案 1 :(得分:1)

我不确定SharePoint集成模式,但ReportServer正确接受通过URL字符串传递的参数。