2012-09-06 27 views
0

我有一個列出學生的可視Web部件。刷新列表webpart以反映在使用visual studio 2010開發的sharepoint 2010中添加的項目

還有一個webpart添加/編輯學生。

部署應用程序後,我創建了新的webpart頁面,並在另一個區域中添加了CreateStudent webpart和另一個區域中的ListStudent webpart。

當我添加一個學生時,我需要在ListStudent webpart的網格中找到那個學生的詳細信息。

我想我需要連接兩個webparts使CreateStudent webpart作爲提供者webpart和ListStudent webpart作爲消費者webpart,但是我的疑問是,我不需要將任何特定值傳遞給ListStudent webpart。

我在ListStudent webpart Page_Load中調用了一個函數,它設置了gridview的數據源並綁定它。如何才能做到這一點?

回答

0

下面是簡單的提供者和使用者Web部件。提供程序UI接受一個文本字段,該字段將其傳遞給使用者Web部件,並將其輸出。 Web部件之間的連接是如下界面:

namespace ConnectedWebParts 
{ 
    public interface IParcel 
    { 
     string ID { get; } 
    } 
} 

供應商網絡部分實現了這個接口,並且必須與屬性的ConnectionProvider返回本身(因爲它實現了接口)的方法:

namespace ConnectedWebParts 
{ 
    public class ProviderWebPart : WebPart, IParcel 
    { 
     protected TextBox txtParcelID; 
     protected Button btnSubmit; 
     private string _parcelID = ""; 

     protected override void CreateChildControls() 
     { 
      txtParcelID = new TextBox() { ID = "txtParcelID" }; 
      btnSubmit = new Button() { ID = "btnSubmit", Text="Submit"}; 
      btnSubmit.Click += btnSubmit_Click; 
      this.Controls.Add(txtParcelID); 
      this.Controls.Add(btnSubmit); 
     } 

     void btnSubmit_Click(object sender, EventArgs e) 
     { 
      _parcelID = txtParcelID.Text; 
     } 

     [ConnectionProvider("Parcel ID")] 
     public IParcel GetParcelProvider() 
     { 
      return this; 
     } 

     string IParcel.ID 
     { 
      get { this.EnsureChildControls(); return _parcelID; } 
     } 
    } 
} 

消費者Web部件必須定義與接受實現了連接接口(提供者Web部件)作爲參數的對象的ConnectionConsumer屬性的方法:

namespace ConnectedWebParts 
{ 
    public class ConsumerWebPart : WebPart 
    { 
     protected IParcel _provider; 
     protected Label lblParcelID; 
     protected override void CreateChildControls() 
     { 
      lblParcelID = new Label(); 
      if (_provider != null && !String.IsNullOrEmpty(_provider.ID)) 
       lblParcelID.Text = _provider.ID;  

      this.Controls.Add(lblParcelID); 
     } 

     [ConnectionConsumer("Parcel ID")] 
     public void RegisterParcelProvider(IParcel provider) 
     { 
      _provider = provider; 
     } 
    } 
} 
相關問題