2011-02-17 72 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。我認爲這兩個連接沒有顯示出來,因爲你不能爲同一個接口提供兩個連接。

相關問題