Author Topic: Selected value of dropdownlist which is inside gridview (Using Javascript)  (Read 9497 times)

BhushanShah

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 73
  • BhushanShah21
    • View Profile
Use below code to find out selected value of Drop Down List which is inside GridView (With Javascript):

Code: [Select]
function SelectedItem() {
            var grid = document.getElementById("GridView1"); //GridView1(ID of the gridview)

            if (grid.rows.length != 0) {
                //loop starts from 1. rows[0] points to the header.
                for (i = 1; i <= grid.rows.length; i++) {
                    var rowone = grid.parentNode.childNodes.item(0).childNodes.item(0).childNodes.item(i).childNodes.item(1);
                    String.prototype.toElement = function() {
                        var t = document.createElement("div");
                        t.innerHTML = this;
                        return t.getElementsByTagName("*")[0];
                    }

                    var sel = rowone.innerHTML.toElement();
                    alert(sel.options[sel.selectedIndex].value); //alert selected value of drop down list
                    alert(sel.options[sel.selectedIndex].text); //alert selected text of drop down list
                }
            }
        }

Regards,
Bhushan Shah
Regards,
Bhushan Shah

Ritesh Shah

  • Administrator
  • Jr. Member
  • *****
  • Posts: 57
  • Ritesh Shah
    • View Profile
    • IT Technology Blog
Re: Selected value of dropdownlist which is inside gridview (Using Javascript)
« Reply #1 on: September 20, 2012, 07:56:53 PM »
very useful script. :)
Ritesh Shah
Administrator
Extreme-Advice.com
SQLHub.com