【问题标题】:How do you get a selected value from gridview dropdown using javascript如何使用 javascript 从 gridview 下拉列表中获取选定的值
【发布时间】:2011-05-17 12:05:07
【问题描述】:

我有一个 gridview,其中有一个列作为下拉列表。当用户选择不同的下拉选项时,我想获得选定的值。我该怎么做?请看下面的代码。此代码似乎在 IE9 和 Firefox 中有效,但在 IE8 中无效。在 IE8 中,我收到以下错误“options.selectedIndex' is null or not an object”。

     var gridview =  document.getElementById('ctl00_ContentPlaceHolder1_grvTrainHistoryCapture');

     if (selectedRowIndex == null) return;
     var statusCell = gridview.rows[parseInt(selectedRowIndex)+ 1].cells[5];
     var ddlStatus = statusCell.childNodes[1];

     var statusID = ddlStatus.options[ddlStatus.options.selectedIndex].value;

【问题讨论】:

    标签: javascript gridview drop-down-menu selectedvalue


    【解决方案1】:

    编辑:我已经在 IE8 下测试了这个代码,它可以正常工作。 我想问题是你传递的对象。

    <script type="text/javascript">     
        var e = document.getElementById('test');
        alert(e.options[e.selectedIndex].value );
    </script> 
    

    【讨论】:

    • 我看到我关于“检查你作为 e 传递的内容”的评论已被删除......我发布的代码 100% 有效。所以剩下的唯一事情就是检查你传递给它的内容。
    【解决方案2】:
        function ShowDropDownValueInGridView(vIndex) {
            //Assume you are passing in the Row Index and your dropdown control is in a Template in cell 2
            Gridview1 = document.getElementById('<%=GridView1.ClientID%>');
            var cell = Gridview1.rows[vIndex].cells[2]
            var dropdownSelectedValue = cell.childNodes[0].value;
            alert(dropdownSelectedValue);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 2022-12-10
      • 2013-09-21
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      相关资源
      最近更新 更多