How to add webpart with connection to Page Layout!!!

Steps :

1. Creating Page Layout
2. Add webpart manually
3. Export webpart
4. Add exported webpart in Feature

SPWebPartConnection wpConnection = null;
string providerWebpart =”ProviderWebpartTitle”

System.Web.UI.WebControls.WebParts.WebPart wpProvider = null;
ProviderConnectionPointCollection providerConnectionPointColl = null;
ConsumerConnectionPointCollection consumerConnectionPointColl = null;
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in WPMgr.WebParts)
if (wp.Title.Equals(providerWebpart, StringComparison.CurrentCultureIgnoreCase))
wpProvider = wp;
providerConnectionPointColl = WPMgr.GetProviderConnectionPoints(wp);

ConsumerConnectionPoint connectionPoint
System.Web.UI.WebControls.WebParts.WebPart wpConsumer =  WPMgr.WebParts[0];
consumerConnectionPointColl = WPMgr.GetConsumerConnectionPoints(wpConsumer);
ProviderConnectionPoint providerConnectionPoint = providerConnectionPointCol[0];
ConsumerConnectionPoint consumerConnectionPoint = consumerConnectionPointColl[0];

wpConnection = WPMgr.SPConnectWebParts(wpProvider, providerConnectionPoint, wpConsumer, consumerConnectionPoint);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s