Articles in this section
Category / Section

How to know how many elements/records were displayed in ListView?

1 min read

How to bind the data to ListView from controller?

In ASP .Net application, the controller data can be fetched with the help of dataManager and the fetched data is bind to the ListView in the success function of dataManager. We can use any data adaptors to fetch the data from Controller.

Refer to the below code snippet to bind the dataSource to ListView.

<script type="text/javascript"> 

 

    document.getElementById('Rech').addEventListener("click", buttonRech_onClick); 

 

    function buttonRech_onClick() { 

         var liste = document.getElementById('ListeMedecins').ej2_instances[0]; 

         var listdata = 

            new ej.data.DataManager({ url: "/RechercheMedecin/LoadData", adaptor: newej.data.WebApiAdaptor }).executeQuery(new ej.data.Query() 

                .addParams('Nom''VALIOS')) 

                .then((e) => {  

                        (e.result).forEach((data) => { 

                            liste.dataSource = e.result; // Filtered data from Controller appended to ListView dataSource 

                           

                        }); 

                    } 

                    liste.dataBind();      

                });        

        

    } 

</script> 

 

 

Refreshing ListView dataSource in Success event

 

In the above code snippet, we are used webapi adaptor to load the controller data url and addParams to add an additional parameter to the ej.data.Query property of dataManager.

In the success event of DataManager, bind the controller data result e.result to ListView.

Display DataSource Count or Length

 

Refer to the below code snippet to get the ListView data items length.

function buttonRech_onClick() { 

         var liste = document.getElementById('ListeMedecins').ej2_instances[0]; 

         var listdata = 

            new ej.data.DataManager({ url: "/RechercheMedecin/LoadData", adaptor: newej.data.WebApiAdaptor }).executeQuery(new ej.data.Query() 

                .addParams('Nom''VALIOS')) 

                .then((e) => {  

                        (e.result).forEach((data) => { 

                            liste.dataSource = e.result; // Filtered data from Controller appended to ListView dataSource 

                        }); 

                        alert('Filtered data Count' + '-' + liste.dataSource.length); // Display Filtered data count or legth from Controller

                    liste.dataBind();      

                });        

        

    } 

 

 

 

Refer to the below sample link.

Sample



Conclusion

I hope you enjoyed learning on how to know how many elements/records were displayed in ListView.

You can refer to our ASP.NET Core ListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NETCore ListView example to understand how to create and manipulate data. For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied