Search code examples
ajaxdatalistitemdatabound

Retrieving values only once without using ItemDataBoundEvent which repeatedly return the value


On DataService.cs, the function returns a list as follows:

[WebMethod()]
public SomeList[] GetListing(

On client side, I have this:

        function onListLoadSuccess(someLists) {            

            var dataList = $find('<%= DataList1.ClientID %>');
            dataList.set_dataSource(someLists);
            dataList.dataBind();

Then when it is bound to DataList1:

        function onListItemDataBound(sender, e) {

            var item = e.get_item();
            if (item.get_isDataItemType()) {

                var someList = item.get_dataItem();
                alert(someList.Country);
                alert(someList.City);

My issue is I only need to retrieve Country and City once, I wonder how I can retrieve those values without using onListItemDataBound function which repeatedly return the value until all the rows has been run through.


Solution

  • Got it to work now.. silly me!

            function onListLoadSuccess(someLists) {  
                alert(someLists[0].City);
                alert(someLists[0].Country);