title: How to change drop down list selected index and visibility using another drop down list in asp.net?
body: <p>I have a drop down list like this in my asp.net application,</p>
  
  <pre><code>&lt;asp:DropDownList runat="server" ID="ddlChanges" CssClass="selectstyle" onchange="javascript:ddlChangesChanged();"&gt; 
  &lt;asp:ListItem Text="-- Select -- " Value="-1"&gt;&lt;/asp:ListItem&gt; 
  &lt;asp:ListItem Text="Status Change" Value="1"&gt;&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Text="Product Name Change" Value="2"&gt;&lt;/asp:ListItem&gt;       
  &lt;asp:ListItem Text="Category Change" Value="3"&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>So, when user selects "Status Change" from the list, another dropdown list with following values appears,</p>
  
  <pre><code>&lt;asp:DropDownList runat="server" ID="ddlStatus" CssClass="selectstyle"  Style="visibility: hidden;"&gt; 
  &lt;asp:ListItem Text="-- Select -- " Value="-1"&gt;&lt;/asp:ListItem&gt; 
  &lt;asp:ListItem Text="Pending" Value="1"&gt;&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Text="Fixed" Value="2"&gt;&lt;/asp:ListItem&gt;       
  &lt;asp:ListItem Text="Cancelled" Value="3"&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  
  &lt;asp:Button ID="btnUpdate" CssClass="selectstyle" runat="server" Text="Update" OnClick="btnUpdate_Click"&gt;&lt;/asp:Button&gt;
  </code></pre>
  
  <p>If user does not select any value from the drop down list (ddlStatus), I am displaying an alert message ("You must select a status.") using JavaScript in the btnUpdate click event,</p>
  
  <pre><code>if (this.ddlStatus.SelectedItem.Value.Trim() == "-1")
  {
      string script = "&lt;script type=\"text/javascript\"&gt;alert('You must select a status.');&lt;/script&gt;";
      ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script);
  }
  </code></pre>
  
  <p>But after this, my page refreshes and drop down list <strong>ddlChanges</strong> has "Status Change" (previously selected item) as selected item and drop down list (ddlStatus) gets hidden. I want ddlChanges drop down list to have -- Select -- as the selected item and <strong>ddlStatus</strong> should be visible.</p>
  
  <p>How can I do that?</p>