listview drilldown into itself

Last post 10-17-2005 2:57 AM by King.Fisher. 8 replies.

Sort Posts:

  • listview drilldown into itself

    10-12-2005, 1:49 PM
    • Member
      230 point Member
    • King.Fisher
    • Member since 09-18-2005, 7:21 AM
    • Posts 46
    There is cool example how to make drilldown from one listview to another at http://www.wilcob.com/wilco/Default/161/showpost.aspx
    It is really usefull in some cases, but what if you need results of second datasource under each item in listview? I tried simply copy second template inside first one, but this doesn't work:
    <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 id="commentsListView">
      <bindings>
        <binding dataContext="commentsDataSource" dataPath="data" property="data" />
      </bindings>
    </listView>

    </listView>
     


    Kick me back on path please...
  • Re: listview drilldown into itself

    10-12-2005, 2:57 PM
    • Participant
      1,454 point Participant
    • WilcoB
    • Member since 03-02-2003, 1:02 PM
    • Posts 290
    Before you want to nest controls such as ListView inside a ListView, you should understand how templates work on a high level. Lets look at a basic template first (simplified):

    HTML:
    <div id="myListView">
    </div>

    <div class="template">
      <div id="myListViewTemplate">
        <div id="myListViewItemTemplate">
          <span id="nameLabel"></span>
        </div>
      </div>
    </div>

    Atlas script:
    <listView targetElement="myListView">
      <layoutTemplate>
        <template layoutElement="myListTemplate" />
      </layoutTemplate>
      <itemTemplate>
        <template layoutElement="myListViewItemTemplate">
          <label targetElement="nameLabel">...</label>
        </template>
      </itemTemplate>
    </listView>

    This is just a ListView which displays a label (span) for each item. When we define a template, such as the item template, we can define what kind of controls the elements inside the context of that template is. In this example we say that the element "nameLabel", inside the element "myListViewItemTemplate", is a label.
    When you bind the listview against for example a datasource with 2 items, Atlas will clone the "myListViewItemTemplate" element to create an item instance that will be added to the DOM. Atlas will look at your Atlas definitions and instantiate and initialize the components associated with the elements inside this item instance.

    In your case, you should do exactly the same with a nested listview as you do with a label.

    That is, you should first define the nested listview inside the parent listview's item template. The HTML for a listview with a nested listview could look something like this:

    <div id="myListView">
    </div>

    <div class="template">
      <div id="myListViewTemplate">
        <div id="myListViewItemTemplate">
          <span id="myNameLabel"></span>
          <div id="myNestedListView">
          </div>
          <div class="template">
            <div id="myNestedListViewTemplate">
              <div id="myNestedListViewItemTemplate">
                <span id="myNestedNameLabel"></span>
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>

    And the Atlas code would then look something like:

    <listView targetElement="myListView" ...>
      <layoutTemplate>
        <template layoutElement="myListTemplate" />
      </layoutTemplate>
      <itemTemplate>
        <template layoutElement="myListViewItemTemplate">
          <label targetElement="nameLabel">...</label>
          <listView targetElement="" ...>
            <layoutTemplate>
              <template layoutElement="myNestedListViewTemplate" />
            </layoutTemplate>
            <itemTemplate>
              <template layoutElement="myNestedListViewItemTemplate">
                <label targetElement="myNestedNameLabel">....</label>
              </template>
            </itemTemplate>
          </listView>
        </template>
      </itemTemplate>
    </listView>

    I haven't actually tried this, but this should work. Please let me know if this makes sense.
    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • Embarrassed [:$] Re: listview drilldown into itself

    10-14-2005, 3:02 AM
    • Member
      230 point Member
    • King.Fisher
    • Member since 09-18-2005, 7:21 AM
    • Posts 46

    Ok, I got it theoretically, I think. When I copied code from your previous master/detail example, it repeats result of query behind under each element of original listview as you can see on http://hidef.asp2.cz/default2.aspx (maybe only in code, it sometimes doesnt work) I think in this scenario I must do other type of data keying then you have in your master/detail example. There should be way to bind that nested listview on load with automatic=false and then do only evaluatein, but I didn't find way how to bind parameter of datasource for nested one from datasource of master one like:

                                     <dataSource id="commentsDS" runat="server" serviceUrl="comments.asmx">
                                         <bindings>
                                             <binding dataContext="??something??" dataPath="text" property="selectParameters" propertyKey="topic" />
                                          </bindings>
                                     </dataSource>

                                        ....
                                     <listView targetElement="CommentsListView" itemTemplateParentElementId="CommentsListViewTemplate" propertyChanged="onChange">
                                          <bindings>
                                            <binding dataContext="commentsDS" dataPath="data" property="data"/>
                                        </bindings>

                                        <layoutTemplate>
                                            <template layoutElement="CommentsListViewTemplate" />
                                        </layoutTemplate>
                                        <itemTemplate>
                                            <template layoutElement="CommentsListViewItemTemplate">
                                               <label targetElement="commentText">
                                                    <bindings>
                                                        <binding dataPath="c_text" property="text"/>
                                                    </bindings>
                                                </label>
                                            </template>
                                        </itemTemplate>
                                      </listView>

  • Re: listview drilldown into itself

    10-14-2005, 6:08 AM
    • Participant
      1,454 point Participant
    • WilcoB
    • Member since 03-02-2003, 1:02 PM
    • Posts 290
    I think your code looks correct. You should leave the data context empty, and set the dataPath to for example "NewsID", which would be a property of the dataitem inside the outer listview. I think that would work.
    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • Embarrassed [:$] Re: listview drilldown into itself

    10-14-2005, 2:33 PM
    • Member
      230 point Member
    • King.Fisher
    • Member since 09-18-2005, 7:21 AM
    • Posts 46
    I don't know if I set right dataPath and if code for setting property is ok, but it doesn't work. You can see what I tried on default.aspx. I'll continue trying...but it looks I'm running in circle again.
  • Re: listview drilldown into itself

    10-14-2005, 4:32 PM
    • Participant
      1,454 point Participant
    • WilcoB
    • Member since 03-02-2003, 1:02 PM
    • Posts 290
    You should declare the comments data source _inside_ the itemtemplate of the listview, in which you have placed the nested listview.
    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • Re: listview drilldown into itself

    10-15-2005, 6:40 AM
    • Member
      230 point Member
    • King.Fisher
    • Member since 09-18-2005, 7:21 AM
    • Posts 46
    It doesnt work Sad [:(]
    I tried set property named newsID and moved datasource first. Then I tried to make dummy control with this id bounded as text and setting datasource parameter by this. Nothing of this works.
    If I got it, atlas creates datasource instance for each item in listview, so I tried simply parametrize by binding this ID directly, as it is on my page now. I don't know why it doesn't work,but I also don't know if it is a good idea to let it work in this way. This mechanism should work fine on my simple page rendering engine with few items. But when I'm tried in classic asp.net create master/detail in this fashion, it was unusable. I solved it by binding to dataset with two related datatables and detail repeater was defined as:
    <asp:repeater id="childRepeater" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' runat="server">
    Are there ..or will be there in future...techniques in atlas which can work same way?
  • Re: listview drilldown into itself

    10-16-2005, 6:22 PM
    • Participant
      1,454 point Participant
    • WilcoB
    • Member since 03-02-2003, 1:02 PM
    • Posts 290
    You can see a demo of a nested listview using atlas at http://www.wilcob.com/atlasnestedlistview. The source for this demo can be downloaded from http://www.wilcob.com/wilco/Downloads/Programming/AtlasNestedListView.zip.

    As you can see, I currently use a button to invoke the nested DataSource. I can't currently think of a way that would automagically let it select data from the service once it is created, without modifying atlas sources or adding a custom control.

    Update: fixed links.
    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • Re: listview drilldown into itself

    10-17-2005, 2:57 AM
    • Member
      230 point Member
    • King.Fisher
    • Member since 09-18-2005, 7:21 AM
    • Posts 46
    It was close..huh..I had dataContext="newsNameLabel" dataPath="ID" instead of dataContext="newsNameLabel" dataPath="dataContext.ID" in one of my testversions. Thanks
Page 1 of 1 (9 items)