Note that there are some explanatory texts on larger screens.

plurals
  1. POset value of dropdown lists in Gridview with javascript
    primarykey
    data
    text
    <p>I have a dropdownlist and a gridview with a drop down list in every row. I have removed other cols in Grid for simplicity. </p> <p>Whenever a new value in the dropdownlist is selected I would like to set all of the dropdownlists in the gridview to that same value via javascript. (Yea both the dropdownlist outside the gird and the ones inside the grid are populated by the same data source)</p> <p>The dropdownlist: </p> <pre><code>&lt;asp:DropDownList onchange="javascript:onJDSelection();" ID="DropDownList3" runat="server" DataSourceID="SqlDataSource4" DataTextField="circt_cstdn_nm" DataValueField="circt_cstdn_user_id"&gt; &lt;/asp:DropDownList&gt; </code></pre> <p>The GridView:</p> <pre><code>&lt;asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" onrowdatabound="GridView2_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Change to Job Designer" SortExpression="circt_Cstdn_nm"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Bind("circt_Cstdn_nm") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:DropDownList ID="ddl_jd" runat="server" DataSourceID="SqlDataSource4" DataTextField="CIRCT_CSTDN_NM" DataValueField="CIRCT_CSTDN_user_id"&gt;&lt;/asp:DropDownList&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>My current attempt: </p> <pre><code>function onJDSelection() { var jd = document.getElementById('ctl00_MAIN_DropDownList3').Text; var grid = document.getElementById('ctl00_MAIN_GridView2'); for (var i = 1; i &lt; grid.rows.length; i++) { grid.rows[i].cells[0].getElementsByTagName("*")[1].selectedText = jd; } } </code></pre> <p>any ideas?</p> <p>Thanks!</p> <p>Update: I tried this.</p> <pre><code>&lt;script type="text/javascript"&gt; function onJDSelection() { var jd = document.getElementById('ctl00_MAIN_DropDownList3').Text; var dropDowns = jQuery('input[id^=ctl00_MAIN_GridView2_ddl_jd]'); alert("test"); alert(dropDowns); var i = 0; dropDowns.each(function () { alert(i); i++; jQuery('#' + jQuery(this) + ':first-child').text(jd); }); } &lt;/script&gt; </code></pre> <p>When clicking on the dropdown I get an alert that says "test" and an alert that says "[Object object]" However nothing happens with the dropdowns in the grid and the alert(i) never fires.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload