0

ドロップダウンとして列の1つを持つグリッドビューがあります。ユーザーが別のドロップダウンオプションを選択すると、選択した値を取得したいと思います。どうすればこれを行うことができますか?以下のコードを参照してください。このコードはIE9とFirefoxで機能するようですが、IE8では機能しません。IE8では、「options.selectedIndex'がnullであるか、オブジェクトではありません」というエラーが発生します。

     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;
4

2 に答える 2

1
    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);
    }
于 2012-04-04T18:17:36.917 に答える
1

編集:私はIE8の下でこのコードをテストしました、そしてそれはそれがそうあるべきであるように働きます。問題はあなたが渡しているオブジェクトだと思います。

<script type="text/javascript">     
    var e = document.getElementById('test');
    alert(e.options[e.selectedIndex].value );
</script> 
于 2011-05-17T12:12:19.107 に答える