0

i have a gridview which has one of the columns as a dropdown. When the user selects a different drop down option i would like to get the selected value. How do i go about this? Please see code below. This code seems to work in IE9 and Firefox but does not work in IE8. In IE8 i get the following error "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;

2 Answers 2

1

EDIT: I HAVE TESTED THIS CODE UNDER IE8, AND IT WORKS AS IT SHOULD. i guess the problem is the object you are passing.

<script type="text/javascript">     
    var e = document.getElementById('test');
    alert(e.options[e.selectedIndex].value );
</script> 
Sign up to request clarification or add additional context in comments.

1 Comment

i see my comment about "check what you are passing as e" was deleted.... the code i have posted 100% works. so the only thing left is to check what you are passing to it.
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);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.