title: Nested listview databinding on button click
body: <p>i have an issue with a client project.</p>
  
  <p>I have a ListView (lv1) of projects which is populated by a ObjectDataSource. I need to code a nested List (lv2) when you click on a button in a row of lv1, the button event should fetch the data then populate lv2. problem is i have tried with a nested ListView but lv2 is not populated onclick.</p>
  
  <pre><code>&lt;asp:ListView id="lv1" runat="server" DataSourceID="foo_ods" OnItemCommand="ListV_Proj_ItemCommand"&gt;
      &lt;LayoutTemplate&gt;
            &lt;table&gt;
                &lt;thead&gt;
                    &lt;tr&gt;
                       &lt;th&gt;Someheader&lt;/th&gt;
                    &lt;/tr&gt;
                &lt;/thead&gt;
                &lt;tr id="itemPlaceholder" runat="server" /&gt;
             &lt;/table&gt;
          &lt;/LayoutTemplate&gt;
          &lt;ItemTemplate&gt;
              &lt;tr&gt;
                 &lt;td&gt;&lt;asp:Button ID="btn_GetSubProj" Text="+" runat="server" CommandArgument='&lt;%# Eval("Master") %&gt;' CommandName="select" /&gt;&lt;/td&gt;
                 &lt;td&gt;data for lv1&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td&gt;
                    &lt;asp:ListView id="lv2" runat="server"&gt;
                        &lt;ItemTemplate&gt;some data&lt;/ItemTemplate&gt;
                    &lt;/asp:ListView&gt;
                  &lt;/td&gt;
               &lt;/tr&gt;
           &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>Codebehind</p>
  
  <pre><code>protected void ListV_Proj_ItemCommand(object sender, ListViewCommandEventArgs e)
  {
      DataTable subProTable = uWeb.Data.Project.List_Test(e.CommandArgument.ToString());
      ListView subListV = (ListView)e.Item.FindControl("lv2");
      subListV.DataSource = subProTable;
      subListV.DataBind();
  }
  </code></pre>
  
  <p>This is the basic structure of the code. Im not sure if it is the right approach. So in short.:</p>
  
  <p>1) Can it be done with a nested ListView ? if yes How and what am i doing wrong?
  2) is there a better way of doing it? only static is the objectdatasource AND the sub lines should only be fetched at button click(so not on lv1 binding). </p>
  
  <p>Result should be a list that you can click a row it then shows the subrows. And because of the amount of data, the sublines(which are identical to the maste rlines in structure) should not be fetched from the db until the button is clicked.</p>
  
  <p><a href="https://i.stack.imgur.com/CvVuM.png" rel="nofollow noreferrer">How it should work</a></p>
  
  <p>I'm abit stressed so sorry if this post is messy. Feel free to tell me if i need to elaborate.</p>