Friday, June 20, 2008

ObjectContainerDataSource in Web Client Software Factory

The Web Client Software Factory contains the data source control ObjectContainerDataSource. This control implements data binding in a way that easily integrates with the View-Presenter pattern.

You can think of the ObjectContainerDataSource control as a container of objects. You programmatically populate the container, and the container raises events when changes occur to any of the contained objects. This design allows the view (Web page) to delegate the responsibility of performing select operations, update operations, delete operations, and insert operations to the presenter.

How to Use ObjectContainerDataSource?

To add ObjectContainerDataSource controll into the toolbox:
right-click the Data tab in the Toolbox, and then select Choose Items. On the .NET FrameworkComponents tab, click Browse, select the Microsoft.Practices.Web.UI.WebControls.dll assembly, and then click Open. Select the ObjectContainerDataSource control in the list of components, and then click OK.

to use it, Drag and drop the control into the UI. Then
1.) Go into Design Mode and click on the Show Smart Tag, and select Configure Data Source..
2.) Noticed that you need to specify a Data Object Type. Select an appropriate object.
3.) Named the container. for instance, MemberDataSource.

For example, to show items when view loads:-
1.) First create a property for set operation in the page code behind.

Public IList memberDS
{
set { MemberDataSource.DataSource = value};
}


2.)To be visible in Presenter, Open IMemberView in the Member module and add a definition as following:


IList memberDS {set;}


3.) go to MemberPresenter, inside the OnViewInitialized method, put this the code.

This.View.memberDS = data... ;


4.) In the page, drag and drop a Grid View, and set its data source attribute to MemberDataSource.

No comments: