Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

I want to ask if i can change the datasource of datalist from javascript or jquery.Since i want to change the datasource without refreshing the page.Or if not,is there anyway to change the datasource without page refresh ?

Thanks in advance.
Posted
Comments
Uday P.Singh 31-Aug-11 14:59pm    
what are the data sources are you using?
mhamad zarif 31-Aug-11 15:06pm    
i want to use the dataset as datasource.Since i am planning to add items to the datalist when user scroll down(like facebook).So i have done the scroll down issue,but in the web method it is calling i am returning a new dataset that has the more items to a javascript function.So i want in this javascript function to change the datasource of the datalist to this returned dataset.
mhamad zarif 31-Aug-11 15:07pm    
please look at my code down.

XML
<script type="text/javascript">
        $(document).ready(function() {

            function lastPostFunc() {
                $('#divPostsLoader').html('<img src="images/bigLoader.gif">');

                //send a query to server side to present new content
                $.ajax({
                    type: "POST",
                    url: "Articles.aspx/ItemsGet",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(data) {

                        if (data != "") {
                           
                        }
                        $('#divPostsLoader').empty();
                    }

                })
            };

            //When scroll down, the scroller is at the bottom with the function below and fire the lastPostFunc function
            $(window).scroll(function() {
                if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                    lastPostFunc();
                }
            });

        });
    </script>


So in the Itemsget method i am returning the new dataset.So in the success function i want to change the datasource of the datalist to this dataset.
 
Share this answer
 
You really don't need to data source to avoid the page refresh. You can use AJAX XMLHTTPRequest or Jquery to Load the data dynamically with out refreshing the page. Jquery .Load() loads data from the server and place the returned HTML into the matched element that provided.
http://api.jquery.com/load/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900