Associate a nested ListView data source with a parent ListView data source

I have thrice-nested ListView controls on my asp.net page, each of which is nested in a different one. I use the OnItemDataBound event in the first ListView to set the DataSource 2nd level ListView. The third ListView is contained in the second ListView. I want to assign the same DataSource to both the ListView 2nd level data source controls and the third level, but I cannot figure out how to access the 3rd level ListView to do this.

Here is an example code to help you visualize:

<asp:ListView id="level1" runat="server" OnItemDataBound="level1_ItemDataBound">
  <layouttemplate>
    <asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
  </layouttemplate>
  <itemtemplate>
    <asp:ListView id="level2" runat="server">
      <layouttemplate>
        <asp:ListView id="level3" runat="server">
          <layouttemplate>
            <asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
          </layouttemplate>
          <itemtemplate>OUTPUT DATA FOR LEVEL 3</itemtemplate>
        </asp:ListView>
      </layouttemplate>
      <itemtemplate>OUTPUT DATA FOR LEVEL 2</itemtemplate>
    </asp:ListView>
    OUTPUT DATA FOR LEVEL 1
  </itemtemplate>
</asp:ListView>

level1_ItemDataBound level2, ListView, DataSource DataBind. , Level3.DataSource , Level2.DataSource. ?

+3
1

DataBind view2 2, ItemDataBound 2.

psuedo:

protected void level1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
  var listView2 = (ListView) e.Item.FindControl("level2");
  listView2.ItemDataBound += level2_ItemDataBound;
  listView2.DataSource = myDataSource;
  listView2.DataBind();
}

protected void level2_ItemDataBound(object sender, ListViewItemEventArgs e)
{
  var listView3 = (ListView) e.Item.FindControl("level3");
  listView3.DataSource = myDataSource;
  listView3.DataBind();
}
+2

Source: https://habr.com/ru/post/1780092/


All Articles