IWebPartParameters makes Connection between Web Parts easy---csdn陈亮
http://blog.csdn.net/savage54321/archive/2008/01/14/2043216.aspx
//Within the class, you need to some method and property of the IWebPartParameters:
private PropertyDescriptorCollection _PD;
[ConnectionProvider("Parameters")]
public IWebPartParameters ConnectionInterface()
{
return this;
}
public void GetParametersData(ParametersCallback callback)
{
IDictionary dic = new Hashtable();
callback.Invoke(dic);
//callback.BeginInvoke(dic);
}
public PropertyDescriptorCollection Schema
{
set { _PD = value; }
get { return _PD; }
}
public void SetConsumerSchema(PropertyDescriptorCollection schema)
{
_PD = schema;
}
Within the class, you need to implement some method and property of the IWebPartParameters:
public IWebPartParameters ConnectionInterface(). The method would be invoked by Consumer, the purpose of the method is to pass the reference of the IWebParameters to the consumer.
public void GetParametersData(ParametersCallback callback). Key method, the remote method within the consumer would be passed in by the ParametersCallback. And you can invoke the peer method by make some callings to the callback, like following.BTW, all parameters was passes by a standard interface’ IDictionary’ .
public PropertyDescriptorCollection Schema. You have to implement the property, even if you don’t like it, ‘cause it’s part of the interface IWebParameters.
public void SetConsumerSchema(PropertyDescriptorCollection schema). The method would be invoked by consumer. Consumer passes the PropertyDescriptorCollection to the provider by calling the method.
Heres' the consumer :
public void GetConnectionInterface(IWebPartParameters providerPart)
{
PropertyDescriptor[] property = { TypeDescriptor.GetProperties(this)["_sDBAlias"] };
PropertyDescriptorCollection schema = new PropertyDescriptorCollection(property);
providerPart.SetConsumerSchema(schema);
ParametersCallback callback = new ParametersCallback(ReceiveParameters);
providerPart.GetParametersData(callback);
}
public void ReceiveParameters(IDictionary Params)
{
// Implement all your logic
}
And then, all the stories are the same, put 2 web part into the same web page, make they connect to each other in editable mode.