How to add items to nested list in Blazor ListView

Answer:

We can able to add the item to the nested list in ListView component using AddItem method.

When we set the target in AddItem method, it will add the corresponding node as children for target element.

publicvoid click() 

     { 

         List<DataModel> data = new List<DataModel>() { 

             new DataModel { 

                Text = "Charlotte", 

                Id="234", 

                Category = "Germany" 

             } 

            }; 

         DataModel list = new DataModel() 

         { 

             Text = "Asia", 

             Id = "01", 

         }; 

         //ListView.AddItem(node, target) 

         this.listView.AddItem(data, list); 

     }


Refer to the below sample link. In this sample, we have added the item by button click.


Loader.
Up arrow icon