sharepoint中两个Web部件之间的多个连接

时间:2011-02-17 15:17:15

标签: sharepoint-2010 web-parts

我是sharepoint的新手。我不知道这是否可能。 我有两个Web部件,一个有两个值,我需要传递给第二个Web部件。 有没有办法做到这一点,或者我只能有一个连接/ 感谢

我有两个可视网页部分。在Provider中,我有两个下拉列表,我需要将值传递给Consumer。这是代码:

公共接口IMyConnection     {         int AreaId {get; }         int TopicId {get; }     }

public class Provider : WebPart, IMyConnection
{
    private Control control;

    protected override void CreateChildControls()
    {
        control = Page.LoadControl(_ascxPath);
        Controls.Add(control);
        base.CreateChildControls();
    }

    public int AreaId
    {
        get { return 1; }
    }

    public int TopicId
    {
        get { return 2; }
    }

    [ConnectionProvider("TopicId", "TopicId", AllowsMultipleConnections = true)]
    public IMyConnection SetTopicConnection()
    {
        return this;
    }

    [ConnectionProvider("AreaId", "AreaId", AllowsMultipleConnections = true)]
    public IMyConnection SetAreaConnection()
    {
        return this;
    }
}

public class Consumer : WebPart
{
    private IMyConnection connection;
    private Control control;

    protected override void CreateChildControls()
    {
        control = Page.LoadControl(_ascxPath);
        Controls.Add(control);
    }

    [ConnectionConsumer("TopicId", "TopicId", AllowsMultipleConnections = true)]
    public void GetTopicConnection(IMyConnection theConnection)
    {
        connection = theConnection;
    }

    [ConnectionConsumer("AreaId", "AreaId", AllowsMultipleConnections = true)]
    public void GetAreaConnection(IMyConnection theConnection)
    {
        connection = theConnection;
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
        if (connection != null)
        {
            //do work
        }
        base.RenderContents(writer);
    }
}

当我尝试设置连接时,它既没有显示连接,也只显示了主题连接。

2 个答案:

答案 0 :(得分:1)

一种解决方案可能是将您的界面拆分为IAreaProvider和ITopicProvider。我认为这两个连接没有显示,因为你不能为同一个接口提供两个连接。

答案 1 :(得分:0)

这取决于Web部件的设计方式。大多数开箱即用的只有一个。如果您编写自己的webpart,则可以根据需要声明任意数量的连接提供程序接口。

相关问题