Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest to change the selected values for the dropdownlists from code behind like this:</p> <pre><code>protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e) { foreach (GridViewRow gvRow in GridView2.Rows) { Control ctrl = gvRow.FindControl("ddl_jd"); DropDownList ddl = ctrl as DropDownList; if (ddl != null) ddl.SelectedIndex = DropDownList3.SelectedIndex; } } </code></pre> <p>Also make sure to set AutoPostBack="true" for DropDownList3. </p> <p>Another approach (that is not very clean or simple) is to add the following code into the Page_Load method (and remove the script block containing onJDSelection function from the .aspx file):</p> <pre><code> if (!Page.IsPostBack) { string functionContent = "&lt;script language=javascript&gt; function onJDSelection()" + "{ var selectedIndex = document.getElementById('" + DropDownList3.ClientID + "').selectedIndex;" + "var grid = document.getElementById('" + GridView2.ClientID + "'); " + "for (var i = 1; i &lt; grid.rows.length; i++) " + "{ var selObj = grid.rows[i].cells[0].getElementsByTagName(\"*\")[0]; selObj[selectedIndex].selected = true;} "+ "}&lt;/script&gt;"; Page.RegisterStartupScript("MyScript", functionContent); DropDownList3.Attributes.Add("onchange", "onJDSelection()"); }. </code></pre> <p>Note that is this case the ID used for retrieving DropDownList3 and GridView2 in javascript are sent from code behind as is not very safe to rely on server control ID's generated by ASP .NET. In case you want to save the dropdownlists values (that are changed using javascript) you will also need additional code.</p> <p>It works based on the following body for aspx page:</p> <pre><code>&lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource1" DataTextField="circt_cstdn_nm" DataValueField="circt_cstdn_user_id" onselectedindexchanged="DropDownList3_SelectedIndexChanged"&gt; &lt;/asp:DropDownList&gt; &lt;asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" onrowdatabound="GridView2_RowDataBound" DataKeyNames="circt_cstdn_user_id"&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="SqlDataSource1" 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; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:TestConnectionString %&gt;" SelectCommand="SELECT * FROM [test]"&gt;&lt;/asp:SqlDataSource&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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