Today, someone asked a question on how to create a master-detail, where the detail was actually related information. Specifically, this person had a list of products, and you could drill-down by clicking on 'comments' to see the comments for that product.

To do this, you could create 2 data sources: the products datasource and the comments datasource. When someone clicks on a comment button of a product, we should first set a ProductID parameter on the comments datasource, which it will pass to the select method on the server. After this property is set, we should actually invoke the select method of that datasource. That's it, basically. The code for this should be something like this:

ASP.NET:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 

<dataSource id="productDataSource" serviceURL="Products.asmx" />
<dataSource id="commentsDataSource" serviceURL="Comments.asmx" />

<listView id="productListView" ....>
  <bindings>
    <binding dataContext="productDataSource" dataPath="data" property="data" />
  </bindings>
  [...]
      <label id="nameLabel">
        <bindings>
          <binding dataPath="ProductName" property="text" />
        </bindings>
      </label>
      <button id="commentsButton">
        <click>
          <setProperty target="commentsDataSource" property="selectParameters" 
            propertyKey="ProductID">
            <bindings>
              <binding dataPath="sender.dataContext.ProductID" property="value" />
            </bindings>
          </setProperty>
          <invokeMethod target="commentsDataSource" method="select" />
        </click>
      </button>
  [...]
</listView>
[...]
<listView id="commentsListView">
  <bindings>
    <binding dataContext="commentsDataSource" dataPath="data" property="data" />
  </bindings>
  [...]
</listView>
[...]

The interesting bit is probably the dataPath in our binding between ProductID and value. Actions (such as setProperty and invokeMethod) have their own data context, to allow you to bind to for example event arguments for the event that was raised. However, we are interested in the data context that holds the product data. There are really at least two ways you can get to that data context: either by using the sender's data context (as shown above), or by explicitly setting the data context of our binding to for example our button control. The latter would look like this:

ASP.NET:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 

[...]
      <button id="commentsButton">
        <click>
          <setProperty target="commentsDataSource" property="selectParameters" 
            propertyKey="ProductID">
            <bindings>
              <binding dataContext="commentsButton" dataPath="dataContext.ProductID" property="value" />
            </bindings>
          </setProperty>
          <invokeMethod target="commentsDataSource" method="select" />
        </click>
      </button>
[...]

Hopefully this answers some questions with relation to bindings and ways to create a drill-down scenario.

Hi Wilco,

I am working on a similar but much simplier scenario in wich I have books and lists of chapters (associated to books).
I need to show the complete list of books, each one with its chapters. I have a Book that contains its name and a string[] list of chapters.
I wanted to show them using a listView looking like this:
<LayoutTemplate>
<atlas:Label ID="lblBookName">
[..]
</atlas:Label>
<ListView ID="lstChapters">
<LayoutTemplate>
<atlas:Label ID="lblChapterName">
....

How can I reference each chapters listView to set data to it? Something like lstChapters[key]?
Or How can I solve this problem without having 2 datasources?

Thanks a lot,
Ariel

Your message will be encoded/formatted when it is displayed. If you want to post code, please put the code inside [code=X][/code] tags, where X is the language of your code (C#, ASPX, SQL, etc).
Name:
Email:
(will be encoded using JavaScript to keep it functional and prevent it from being picked up by spammers)
Url:
 
Message:
3 + 3 =