views:

19

answers:

1

I have a dropdownlist, and a Gridview where one of the columns is a dropdownlist.

both dropdown lists use the same data source.

When a value is selected in the dropdownlist (outside the gridview) I want to chaneg the selectedValue and selectText of every dropdownlist in my gridview.

This is what I have tried:

Dropdownlist:

<asp:DropDownList onclick="javascript:onJDSelection()" ID="DropDownList3" runat="server" 
        DataSourceID="SqlDataSource4" DataTextField="circt_cstdn_nm" 
        DataValueField="circt_cstdn_user_id">

Javascript:

<script type="text/javascript">
function onJDSelection() {

    var jd = document.getElementById('DropDownList3.ClientID').selectedText;
    var grid = document.getElementById('GridView2.ClientID');
    //Loop starts from 1 because the zeroth row is the header.   
    for (var i = 1; i < grid.rows.length; i++) {

        var OtherText = grid.rows[i].cells[2].innerText; // Works fine   

        grid.rows[i].cells[3].getElementsById('ddl_JD').selectedText = jd;

    }
}

When I click I get an error. It says object expected. However I know those objects exsist!

Any ideas? Thanks!

+1  A: 

You could use the DOM model instead of getting the dropdownlist directly per ID(ASP.Net changes your 'ddl_JD'). You know at least the cell(grid.rows[i].cells[3]). So try nextSibling ...

Tim Schmelter