title: c# dropdownlist selectedindexchanged in gridview sets selectedindex of second dropdownlist
body: <p>I have a gridview with two dropdownlists populated from a db. One is a descriptive name, the other is an abbreviated name. I need to accomplish the following:</p>
  
  <p>When I select an item in DDL1 I need to change the selected index of DDL2 to match, and vice versa.</p>
  
  <p>I have searched on here and found the following:</p>
  
  <pre><code>protected void ddlAddLabTest_SelectedIndexChanged(object sender, EventArgs e)
  {
     DropDownList ddlLabTest = (DropDownList)sender;
     GridViewRow row = (GridViewRow)ddlLabTest.NamingContainer;
     DropDownList ddlAddLabTestShortName = (DropDownList)row.FindControl("ddlAddShortname");
  
     ddlAddLabTestShortName.SelectedIndex = intSelectedIndex;
  }
  </code></pre>
  
  <p>Only when it gets to the assignment for "row" I receive the following:</p>
  
  <pre><code>Unable to cast object of type 'System.Web.UI.WebControls.DataGridItem' to type 'System.Web.UI.WebControls.GridViewRow'.
  </code></pre>
  
  <p>I have tried finding a working example but I can't. Any help is greatly appreciated!</p>