Looping through GridView with Javascript on the client side

by rBellantoni 9/16/2009 12:24:00 PM

Every had to find a specific control inside of a gridview on the client side or grab a group of controls to manipulate them. Here is how to grab controls in the gridview with javascript:

function GetTotal() {
            totalDTH = 0;
            totalMCF = 0;

            // Get the gridview
            var grid = document.getElementById("<%= grdVolumes.ClientID%>");

            // Get all the input controls (can be any DOM element you would like)
            var inputs = grid.getElementsByTagName("input");

           // Loop through all the DOM elements we grabbed
           for (var i = 0; i < inputs.length; i++) {

                // In this case we are looping through all the Dek Volume and then the Mcf volume boxes in the grid and not an individual one and totalling them
                if (inputs[i].name.indexOf("txtDekVolume") > 1) {
                    if (inputs[i].value != "") {
                        totalDTH = totalDTH + parseInt(inputs[i].value);
                    }

                }
                if (inputs[i].name.indexOf("txtMcfVolume") > 1) {
                    if (inputs[i].value != "") {
                        totalMCF = totalMCF +  parseInt(inputs[i].value);
                    }

                }
            }
        }

Tags:

Comments

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  November 2020  >>
MoTuWeThFrSaSu
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2020

Sign in