title: Getting selected Index of dropdown using asp.net C#
body: <p>I have a dropdown like this:</p>
  
  <pre><code>   &lt;asp:DropDownList ID="CompaniesDropDownList" runat="server" DataSourceID="CompaniesObjectDataSource"
                       DataTextField="NameLang1" DataValueField="CompanyID" AppendDataBoundItems="True"
                       AutoPostBack="true"&gt;
          &lt;asp:ListItem Value="0" Text="select a company"&gt;&lt;/asp:ListItem&gt;
     &lt;/asp:DropDownList&gt;
     &amp;nbsp;
     &lt;asp:ObjectDataSource ID="CompaniesObjectDataSource" runat="server" TypeName="HRCompany"
         SelectMethod="GetList"&gt;&lt;/asp:ObjectDataSource&gt;
     &lt;asp:CustomValidator ID="CompanyCustomValidator" runat="server" ErrorMessage="select a company"&gt;&lt;/asp:CustomValidator&gt;
  </code></pre>
  
  <p>I am setting its selected value like this:</p>
  
  <pre><code>CompaniesDropDownList.SelectedItem.Value = "3";
  </code></pre>
  
  <p>and it is working.</p>
  
  <p>after setting this value, I am checking in if condition, the selected index or value like this:</p>
  
  <pre><code>if (CompaniesDropDownList.SelectedValue == "0")
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if (CompaniesDropDownList.SelectedIndex == 0)
  </code></pre>
  
  <p>and it is always true. Although in dropdownlist on front end, item with value 3 is selected.</p>
  
  <p>How to get selected index of this dropdown ?</p>
  
  <p>Please suggest</p>