title: How to set dropdownlist from code behind?
body: <p>I have the following DropDownList:</p>
  
  <pre><code>&lt;asp:DropDownList ID="commission" class="form-control" runat="server"&gt;
      &lt;asp:ListItem Enabled="true" Text="Select Commission" Value="-1"&gt;&lt;/asp:ListItem&gt;
      &lt;asp:ListItem Text="10%" Value="0.1"&gt;&lt;/asp:ListItem&gt;
      &lt;asp:ListItem Text="15%" Value="0.15"&gt;&lt;/asp:ListItem&gt;
      &lt;asp:ListItem Text="20%" Value="0.20"&gt;&lt;/asp:ListItem&gt;
      &lt;asp:ListItem Text="25%" Value="0.25"&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>I am reading value of dropdown list from database. I get object reference not set to an instance of an object Error.
  This is what I have tried:</p>
  
  <pre><code>double com = reader.GetDouble(6);
  if (com == 0.1)
  {
      commission.Items.FindByText("10").Selected = true; // I get the exeption here
  }
  else if (com == 0.15)
  {
      commission.Items.FindByText("15").Selected = true;
  }
  else if (com == 0.2)
  {
      commission.Items.FindByText("20").Selected = true;
  }
  else if (com == 0.25)
  {
      commission.Items.FindByText("25").Selected = true;
  }
  </code></pre>