AjaxDataControls (ADC) FAQ - Loop through the items

Sometimes you may want to loop through all the items in any of the ADCControls after it has been bound. The following code demonstrates this:

function loopItems()
{
    var items = dataList.get_items();
    for (var item in items)
    {
      // do something.
    }
}

Now in the case you are searching for a certain bound property inside the control you can add the following code section inside the loop:

var dataItem = items[item].get_dataItem();
// We are looking for the image where the image name is "img0"
if (dataItem.image == "img0")
{
  index = items[item].get_itemIndex();
  break;
}

Here is the completed function:

function getItem()
{
    var index = -1;
    var items = dataList.get_items();
    for (var item in items)
    {
        var dataItem = items[item].get_dataItem();
        if (dataItem.image == "img0")
        {
            index = items[item].get_itemIndex();
            alert(index);
            break;
        }
    }
   
    return index;
}

Published Friday, June 13, 2008 12:03 PM by Sonu

Comments

# AjaxDataControls (ADC) FAQ - INDEX

Friday, June 13, 2008 11:04 PM by Sonu on .NET

Welcome to the AjaxDataControls FAQ. How to get started with the AjaxDataControls with Visual Studio

# re: AjaxDataControls (ADC) FAQ - Loop through the items

Tuesday, September 23, 2008 11:19 PM by renasis

How would you do similar on ajaxdatacontrol gridview? I would like to loop through the rows and get items.

# re: AjaxDataControls (ADC) FAQ - Loop through the items

Wednesday, September 24, 2008 9:37 AM by Sonu

function loopItems() {

   var rows = grid.get_rows();

   for (var row in rows)

   {

       var dataItem = row.get_dataItem();

   }

}

# re: AjaxDataControls (ADC) FAQ - Loop through the items

Wednesday, September 29, 2010 10:15 PM by mohanms

How can I get the data at the back end code? I'm using VS2005 with c#. But I don't mind if its using VB also. Thanks

# re: AjaxDataControls (ADC) FAQ - Loop through the items

Wednesday, September 29, 2010 10:16 PM by mohanms

How would i do this at the back end code? Loop through the grid and get the data at the back end code?

# re: AjaxDataControls (ADC) FAQ - Loop through the items

Thursday, September 30, 2010 9:57 AM by Sonu

Mohan, I am not sure what exactly you mean. Can you elaborate please?