2011-02-17 120 views
1

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

我有两个可视的Web部件。在提供者中,我有两个下拉列表,我需要将值传递给消费者。以下是代码:

public interface 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); 
    } 
} 

当我尝试设置的连接,它不同时显示,但只设置主题连接。

回答

0

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

1

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