ansoesil’s blog

“Learning is experience. Everything else is just information.” – Albert Einstein

In Depth: Data Binding with Intersoft Presenter for Silverlight – Part2

with one comment

Hi all,

In the previous post we discuss about the various factor that you can do with data binding with intersoft presenter. Now i want to discuss about how to add additional query / custom query and how to change the data source of intersoft presenter at run time.

Using custom query

Often in developing an application we perform more complex query rather just selecting all the data and display it, and how can we achieve that using Intersoft Presenter and Intersoft Data Source?

As mentioned before there are two types of data binding in Intersoft Presenter:

  1. Bound to Intersoft Data Source control.
  2. Unbound to Intersoft Data Source control.

In unbound to Intersoft Data Source control, the developer only need to specify the ItemSource with the processed data source, so developer is responsible to give the ItemsSource with the correct data.

In bound to Intersoft Data Source control, the developer can interrupt the selecting process using Intersoft Data Source’s Selecting event handler and provide the custom query there.

InDepth2-DataBinding

Attach Selecting Event

Add the custom query at code behind.

InDepth2-DataBinding1

InDepth2-DataBinding2

Note that you might want to keep some of the sort / filter / paging expression from the actual data source select arguments. The above code shows you how to initialize the query and then put the custom / additional filter after it.

In this case i’m adding additional filter (Discontinued == false) so that it will shows Products data with page size of 20 and filter-out the discontinued products.

Changing Data Source at runtime

We also often developing an application where it requires us to change the data source of our presenter, you can do that by changing the data member of your presenter (for Bound to Intersoft Data Source control scenario) and call RefreshData(true) method, or you can specify the new ItemsSource using RefreshData(newItemSource, true) for Unbound to Intersoft Data Source control scenario.

InDepth2-DataBinding3

During combox box items selection changed:

InDepth2-DataBinding4

Results:

InDepth2-DataBinding5

InDepth2-DataBinding6

If you want to see the sample code, you can download it from here.

Regards

Andry

Written by ansoesil

July 17, 2009 at 12:57 pm

Posted in General

One Response

Subscribe to comments with RSS.

  1. to run the specific samples in this post, change the following code in app.cs

    private void Application_Startup(object sender, StartupEventArgs e)
    {
    // In Depth Data Binding – part 2

    // this.RootVisual = new InDepth_DataBinding2_CustomQuery();
    // this.RootVisual = new InDepth_DataBinding2_ChangeDataSource();
    }

    open one of the commented code.

    ansoesil

    July 22, 2009 at 9:09 pm


Leave a comment