SharePoint 2010 编程链接两个web part
- Get the SPLimitedWebPartManager instance on the page;
- Get the provider and consumer Web parts need to be connected;
- Get the connection points for the provider and consumer Web parts;
- Connect them using SPConnectWebParts method. If necessary, certain transforming needs to be in place for compatible interfaces
SPWeb web = (SPWeb)properties.Feature.Parent; SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared); System.Web.UI.WebControls.WebParts.WebPart provider= mgr.WebParts["Provider"]; System.Web.UI.WebControls.WebParts.WebPart consumer= mgr.WebParts["Consumer"]; ConsumerConnectionPoint addConsumerConnPoint = mgr.GetConsumerConnectionPoints(consumer)["AddressConsumer_ot"]; ProviderConnectionPoint addProviderConnPoint = mgr.GetProviderConnectionPoints(provider)["AddressProvider_ot"]; mgr.SPConnectWebParts(provider, addProviderConnPoint, consumer, addConsumerConnPoint);