Connected WebPart

Connected Web Parts make it easy to share data across Web Parts that are running on your page or, more formally, allow your interactions with one Web Part to other Web Parts.

We need four things to create connected Web Parts:

. A custom interface for data
. A Custom Web Part treat as provider
. A Custom Web Part treat as consumer
. A connection between the two Web Parts which will be don on sharepoint application page.

In this I will take Employee and Department table relation example which will be using above four steps to implement custom connected Web Parts.

SharePoint List Structure Images:

I have created Emp and Dept List. See below images:-

Solution Structure

I have created usual WSP Builder project to implement this connected web part functionality.

Creating the Data Interface

We define what data will be served up by our provider Web Part by creating a contract,which is actually an interface that is defined in our code.
This interface is implemented by the provider Web Part so that consumers will know what data will be sent to them by the provider.

1
2
3
4

publicinterface ISelectedEmpID
{string EmpId {get;}}

The EmpId property is the actual data point that will be passed to the consumer Web Part and will be used to detail department for a selected employee.

Provider webpart class (EmpIDProvider.cs)

Provider class must inherit the interface that defines the data that will be provided to any consuming Web Parts. Also any properties and methods that are defined by the interface must be implemented.

In this example, the class must have a EmpId property. We must define a method that will return an instance of the implemented interface. See below code:-