Dynamically populating and setting value in dropdownlist in ASP.Net
<p>I have a form where I have 4 dropdowns Country, State, District and City. Country is populated on form load and rest are populated on selected index changed event. The sequence is On Country's selected index changed States are populated. On State-> Districts populated and on Districts -> Cities are populated. </p>

<p>For saving it worked fine but when i was updating value, it shows null reference error. On debugging I got, the dropdowns are not populated, whereas I was trying set values. Below is my code.</p>

<pre><code>using (var manager = new LocationManager())
        {
            var dt = manager.GetLocationById(i);
            if (dt.Rows.Count == 1)
            {
                Countries.SelectedValue = Countries.Items.FindByText(dt.Rows[0]["Country"].ToString()).Value;
                BindStates(Convert.ToInt32(Countries.SelectedItem.Value));

                States.SelectedValue = States.Items.FindByText(dt.Rows[0]["State"].ToString()).Value;
                BindDistricts(Convert.ToInt32(States.SelectedItem.Value));

                Districts.SelectedValue = Districts.Items.FindByText(dt.Rows[0]["District"].ToString()).Value;
               BindCities(Convert.ToInt32(Districts.SelectedItem.Value));

                Cities.SelectedValue = Cities.Items.FindByText(dt.Rows[0]["City"].ToString()).Value;
                Pincode.Text = dt.Rows[0]["Pincode"].ToString();

                ViewState["Id"] = dt.Rows[0]["LocationId"].ToString();



            }
        }
</code></pre>

<p>I am getting error: {"Object reference not set to an instance of an object."} at method  </p>

<blockquote>
  <p>BindStates(Convert.ToInt32(Countries.SelectedItem.Value));</p>
</blockquote>
