views:

927

answers:

2

I have an ASP.NET Datagrid with serveral text boxes and drop down boxes inside it. I want to read all the values in the grid using a javascript function. How do i go about it?

+2  A: 

Easily done with jQuery. I don't recall what kind of markup the Datagrid creates but basically something like this will work in Jquery

    $('#client_id_of_datagrid input, #client_id_of_datagrid select')
.each(function() {val = this.value; /* Do Stuff */})
Rodrick Chapman
A: 

And here's an example using Microsoft AJAX framework:

var txts = $get('client_id_of_datagrid').getElementsByTagName('input');
var ddls = $get('client_id_of_datagrid').getElementsByTagName('select');

for(var i=0;i<txts.length;i++){
  if(txts[i].type==='text'){
    /* do stuff */
  }
}

for(var i=0;i<ddls.length;i++){
  /* do stuff */
}

And for no framework replace $get with document.getElementById. Really, jQuery is the best idea.

Slace