Sharepoint 自定义筛选器 Web 部件

发布于 2024-07-10 03:31:19 字数 1527 浏览 7 评论 0原文

我想创建一个自定义 Web 部件,该部件具有超过 1 个筛选器 Web 部件,并且可以在运行时/设计时连接到报表查看器 Web 部件(集成模式)。

我对此进行了很多搜索,但找不到一种方法来让单个 Web 部件成为多个过滤器的提供者。

举例来说 -

  1. 我的 Report 接受 2 个参数 DepartmentRegion
  2. 我想将这两个参数与具有两个下拉列表的单个 Web 部件连接(一个用于 Department,一个用于 Region),
  3. 两个下拉列表中的值都应传递给 DepartmentRegion
  4. Report 应在报表查看器 Web 部件中呈现

到目前为止尝试过的解决方案

  1. 创建一个添加两个自定义放置的 Web 部件down
  2. ITransformableFilterValues 实现的自定义下拉类
  3. 在 Web 上有 2 个方法,每个方法都有 ConnectionProvider 属性并返回下拉控件的实例

问题:

尽管我的自定义过滤器 Web 部件上显示了 2 个连接选项,但只能添加一个。 例如,如果我将 Filter1(自定义 Web 部件)连接到 Department,则我无法再次将其连接到 Report Viewer Web 部件。

我的网络部件有这样的方法:  

[ConnectionProvider("Departmet", "UniqueIDForDept", AllowsMultipleConnections = true)] 
public ITransformableFilterValues ReturnCity() 
{ 
    return dropDownDepartment; // It implemets ITransformableFilterValues 
} 

[ConnectionProvider("Region", "UniqueIDForRegion", AllowsMultipleConnections = true)] 
public ITransformableFilterValues ReturnMyRegionB() 
{ 
    return dropDownRegion; //It implemets ITransformableFilterValues 
}

I want to create a custom web part that has more than 1 filter web part and that can be connected to Report Viewer Web Part (Integrated Mode) at runtime/design time.

I searched a lot for this, but could not find a way to have single web part that is a provider to more than 1 filters.

Say for example -

  1. My Report accepts 2 parameter Department and Region
  2. I want to connect both parameters with single web part having two drop down (one for Department and one for Region)
  3. Values from both the drop down should be passed to Department and Region
  4. Report should be rendered in Report Viewer Web Part

Solution Tried so far

  1. Create a web part that adds two custom drop down
  2. Custom drop down class that implements from ITransformableFilterValues
  3. Have 2 methods on the web pat each having ConnectionProvider attribute and return instance of drop down control

Problem:

Even though 2 connection option is shown on my custom filter web part only one can be added.
For example if I connect Filter1(custom web part) to Department then I am unable to connect it to Report Viewer web part again.

My web part have methods like this:  

[ConnectionProvider("Departmet", "UniqueIDForDept", AllowsMultipleConnections = true)] 
public ITransformableFilterValues ReturnCity() 
{ 
    return dropDownDepartment; // It implemets ITransformableFilterValues 
} 

[ConnectionProvider("Region", "UniqueIDForRegion", AllowsMultipleConnections = true)] 
public ITransformableFilterValues ReturnMyRegionB() 
{ 
    return dropDownRegion; //It implemets ITransformableFilterValues 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖心男生 2024-07-17 03:31:19

我做了类似的事情。 这可能会帮助您指明正确的方向。 我使用表单库中的数据来创建详细的报告。 我使用报告服务并使用 Web 服务连接到共享点。 http://server/_vti_bin/Lists.asmx。 我使用的报告参数是项目 ID 或 GUID。 然后我配置了我的报告查看器。 在表单库上,我使用 JavaScript 覆盖上下文菜单以添加“查看报告”。 在报告页面上,我使用查询字符串过滤器从 url 中获取项目 ID。

I did something similar. This might help point you in the right direction. I used data in a form library to create a detailed report. I used reporting services and connected to sharepoint using web services. http://server/_vti_bin/Lists.asmx. The report parameter I used was the item ID or GUID. Then I configured my report viewer. On the form library I used JavaScript to override the context menu to add "View Report". On the report page I used a Query String filter to grab the item ID out of the url.

月下凄凉 2024-07-17 03:31:19

不确定您是否能够解决您的问题。

实际上我尝试使用 AllowsMultipleConnections = true 并且效果很好:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;


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 System.Collections.Generic;
using Microsoft.SharePoint.Utilities;

namespace FromMultiSource
{
    [Guid("a0d068dd-9475-4055-a219-88513e173502")]
    public class MultiSource : aspnetwebparts.WebPart
    {
        List<wsswebparts.IFilterValues> providers = new List<wsswebparts.IFilterValues>();
        public MultiSource()
        {
        }

        [aspnetwebparts.ConnectionConsumer("Multiple Source Consumer", "IFilterValues", AllowsMultipleConnections = true)]
        public void SetConnectionInterface(wsswebparts.IFilterValues provider)
        {
            this.providers.Add(provider);
            if (provider != null)
            {
                List<wsswebparts.ConsumerParameter> l = new List<wsswebparts.ConsumerParameter>();
                l.Add (new wsswebparts.ConsumerParameter ("Value", wsswebparts.ConsumerParameterCapabilities.SupportsMultipleValues | Microsoft.SharePoint.WebPartPages.ConsumerParameterCapabilities.SupportsAllValue));
                provider.SetConsumerParameters(new ReadOnlyCollection<wsswebparts.ConsumerParameter>(l));
            }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // TODO: add custom rendering code here.
            // Label label = new Label();
            // label.Text = "Hello World";
            // this.Controls.Add(label);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            base.RenderContents(writer);
            this.EnsureChildControls();
            foreach (wsswebparts.IFilterValues provider in this.providers)
            {
                if (provider != null)
                {
                    string prop = provider.ParameterName;
                    ReadOnlyCollection<string> values = provider.ParameterValues;
                    if (prop != null && values != null)
                    {
                        writer.Write("<div>" + SPEncode.HtmlEncode(prop) + ":</div>");
                        foreach (string v in values)
                        {
                            if (v == null)
                            {
                                writer.Write("<div>  <i>"(empty)"/null</i></div>");
                            }
                            else if (v.Length == 0)
                            {
                                writer.Write("<div>  <i>empty string</i></div>");
                            }
                            else
                            {
                                writer.Write("<div>  " + v + "</div>");
                            }
                        }
                    }
                    else
                    {
                        writer.Write("<div>No filter specified (all).</div>");
                    }

                }
                else
                {
                    writer.Write("<div>Not connected.</div>");
                }

                writer.Write("<hr>");
            }
        }
    }
}

Not sure if you were able to fix your problem..

Actually I tried with AllowsMultipleConnections = true and it worked fine:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;


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 System.Collections.Generic;
using Microsoft.SharePoint.Utilities;

namespace FromMultiSource
{
    [Guid("a0d068dd-9475-4055-a219-88513e173502")]
    public class MultiSource : aspnetwebparts.WebPart
    {
        List<wsswebparts.IFilterValues> providers = new List<wsswebparts.IFilterValues>();
        public MultiSource()
        {
        }

        [aspnetwebparts.ConnectionConsumer("Multiple Source Consumer", "IFilterValues", AllowsMultipleConnections = true)]
        public void SetConnectionInterface(wsswebparts.IFilterValues provider)
        {
            this.providers.Add(provider);
            if (provider != null)
            {
                List<wsswebparts.ConsumerParameter> l = new List<wsswebparts.ConsumerParameter>();
                l.Add (new wsswebparts.ConsumerParameter ("Value", wsswebparts.ConsumerParameterCapabilities.SupportsMultipleValues | Microsoft.SharePoint.WebPartPages.ConsumerParameterCapabilities.SupportsAllValue));
                provider.SetConsumerParameters(new ReadOnlyCollection<wsswebparts.ConsumerParameter>(l));
            }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // TODO: add custom rendering code here.
            // Label label = new Label();
            // label.Text = "Hello World";
            // this.Controls.Add(label);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            base.RenderContents(writer);
            this.EnsureChildControls();
            foreach (wsswebparts.IFilterValues provider in this.providers)
            {
                if (provider != null)
                {
                    string prop = provider.ParameterName;
                    ReadOnlyCollection<string> values = provider.ParameterValues;
                    if (prop != null && values != null)
                    {
                        writer.Write("<div>" + SPEncode.HtmlEncode(prop) + ":</div>");
                        foreach (string v in values)
                        {
                            if (v == null)
                            {
                                writer.Write("<div>  <i>"(empty)"/null</i></div>");
                            }
                            else if (v.Length == 0)
                            {
                                writer.Write("<div>  <i>empty string</i></div>");
                            }
                            else
                            {
                                writer.Write("<div>  " + v + "</div>");
                            }
                        }
                    }
                    else
                    {
                        writer.Write("<div>No filter specified (all).</div>");
                    }

                }
                else
                {
                    writer.Write("<div>Not connected.</div>");
                }

                writer.Write("<hr>");
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文