Thomas
Thomas

Reputation: 34218

How to iterate a gridview by javascript

Suppose my gridview has a few rows and every row has a few textboxes. I want to iterate the gridview with JavaScript to read the value of each textbox. How easily can I achieve it by plain JavaScript or jQuery? I want a cross browser solution.

Upvotes: 0

Views: 158

Answers (2)

ahsteele
ahsteele

Reputation: 26514

Definitely use jQuery. I use a couple of different jQuery selectors below. This should give you a general idea of how to accomplish your goal.

$('#gridviewId').find('.textClass').each(function () { alert($(this).val()) });

The above code would use the grid view's id and then would find all of the descendant elements with a particular class (in your case textboxes) alerting their value. I've added a working example at: http://jsfiddle.net/GWAAC/.

Upvotes: 2

Ron Harlev
Ron Harlev

Reputation: 16723

use jQuery. If you know the class or ID of the elements you need, a simple selector will return all of them

Upvotes: 1

Related Questions