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:
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:
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.