2

I have create a Web Part Page and I have added two web parts, the parent is List of Person and the child is a List of Person's Address. When I connect these two webparts in code the code executed successfully and when I view the page it doesn't seem to be connected because the filtering is not working.

I had to open the web part connect dialog from the UI, but I had to click finish since connection points were already selected correctly and everything works!

So why is the code created the connection point correctly but didn't link the two list?

Code:

var file = web.GetFile("SitePages/persons.aspx");
var wpManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

var consumerWebPart = wpManager.WebParts.Cast<WebPart>().FirstOrDefault(x => x.Title == "personaddress");
var providerWebPart = wpManager.WebParts.Cast<WebPart>().FirstOrDefault(x => x.Title == "person");

var consumerConnectionPoints = wpManager.GetConsumerConnectionPoints(consumerWebPart);
var consumerConnectionPoint = consumerConnectionPoints["DFWP Filter Consumer ID"];

var providerConnectionPoints = wpManager.GetProviderConnectionPoints(providerWebPart);
var providerConnectionPoint = providerConnectionPoints["DFWP Row Provider ID"];

var transformer = new RowToParametersTransformer();
transformer.ConsumerFieldNames = new string[] {"lookupperson"};
transformer.ProviderFieldNames = new string[] {"ID"};

var connection = wpManager.SPConnectWebParts(providerWebPart, providerConnectionPoint,consumerWebPart, consumerConnectionPoint, transformer);
wpManager.SPWebPartConnections.Add(connection);
4
  • Please post your code so people can see what might be missing Feb 27, 2014 at 13:33
  • added my code in the questions now. Feb 27, 2014 at 14:50
  • You should dispose your WPManager, probably not the solution but it will leak memory otherwise (same with web) Feb 27, 2014 at 14:53
  • I left out the using() part of the code. Yes I should doing the same with the wpmanager. This code runs ok, but will connect when I edit the page. Feb 27, 2014 at 14:57

1 Answer 1

1

solved my own problem, the provider field name should be "Title" because the lookupperson field is ShowField="Title".

Connections all working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.