title: checkboxlist selectedindexchanged event c# not working
body: <p>I've got a checkboxlist on my asp.net page. I'm populating it with countries. I've added a "SelectedIndexChanged" event that is supposed to check that if one of the selected countries is Africa, it should make a textbox visible, otherwise visible=false if it is not selected. I have changed the AutoPostback to true. But the problem that I'm having is that it is not doing an autopostback (it's not going into the method at all). Could somebody please help me on this?</p>
  
  <p>This is what I've done:</p>
  
  <pre><code>     &lt;div id="div1" style="overflow-x:auto; width:100%; max-width:100%; height:150px; max-height:150px;" runat="server"&gt;
        &lt;asp:CheckBoxList ID="lstLocations" CssClass="CheckBoxList" runat="server" Width="40%" Height="100%" AutoPostBack="True" OnSelectedIndexChanged="lstLocations_SelectedIndexChanged" &gt;
        &lt;/asp:CheckBoxList&gt;
       &lt;/div&gt;
  </code></pre>
  
  <p>Populating the checkboxlist:</p>
  
  <pre><code>     private void CreateRegionList()
      {
          lstLocations.Items.Clear();
  
          cn = new SqlConnection(GetConnectionString());
          SqlCommand myCmd = new SqlCommand("SELECT ID, Region FROM CanonSALeads_Region ORDER BY Region", cn);
          cn.Open();
          SqlDataReader myReader = myCmd.ExecuteReader();
  
          lstLocations.AutoPostBack = false;
          lstLocations.CellPadding = 5;
          lstLocations.CellSpacing = 5;
          lstLocations.RepeatColumns = 1;
          lstLocations.RepeatDirection = RepeatDirection.Vertical;
          lstLocations.RepeatLayout = RepeatLayout.Flow;
          lstLocations.TextAlign = TextAlign.Right;
          lstLocations.CssClass = "CheckBoxList";
  
          if (myReader.HasRows)
          {
              while (myReader.Read())
              {
                  CheckBox cb = new CheckBox();
                  cb.ID = myReader[0].ToString();
                  cb.Text = myReader[1].ToString();
                  cb.AutoPostBack = false;
                  cb.CssClass = "CheckBox";
  
                  lstLocations.Items.Add(new ListItem(myReader[1].ToString(), myReader[0].ToString()));
                  lstLocations.Controls.Add(new LiteralControl("&lt;br&gt;"));
              }
          }
          cn.Close();
          myReader.Close();
      }
  </code></pre>
  
  <p>And this is my selectedIndexChanged event:</p>
  
  <pre><code>    protected void lstLocations_SelectedIndexChanged(object sender, EventArgs e)
      {
          string value = null;
          try
          {
              foreach (ListItem checkBox in lstLocations.Items)
              {
                  if (checkBox.Selected == true)
                  {
                      value = checkBox.Text;
  
                      if (value == "Africa")
                      {
                          txtCountryOfAfrica.Visible = true;
                          lblAfricaCountry.Visible = true;
                      }
                  }
                  else
                  {
                      value = checkBox.Text;
  
                      if (value == "Africa")
                      {
                          txtCountryOfAfrica.Visible = false;
                          lblAfricaCountry.Visible = false;
                      }
                  }
              }
  
          }
          catch (Exception ex)
          {
              string msg = "Select Error:";
              msg += ex.Message;
              throw new Exception(msg);
          }
  
      }
  </code></pre>
  
  <p>Page_Load method:</p>
  
  <pre><code>     protected void Page_Load(object sender, EventArgs e)
      {
          string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
          txtUser.Text = userName;
  
          if (!IsPostBack)
          {
              ContainerDocumentation.ActiveTab = tabAddCustomer;
              PopulateSector();
              CreateRegionList();
              PopulateOpportunitySource();
              CreatelstProductGroupList();
              PopulateStatus();
  
              PopulateTenders();
              PopulateOtherOpportunityType();
          }
      }
  </code></pre>