title: Populate ListBox from List<string>
body: <p>I'm missing something very simple here...I've stepped through my debugger and everything is working, but the ListBox is not being populated with the new data. It is showing as empty when I run the site.</p>
  
  <p>I want to:</p>
  
  <p>Step.1 Populate the Listbox with filepath strings from my database. (This is ok)</p>
  
  <p>Step.2 Create a new List using the ListBox items, removing the path from each string in the process. (This seems to be ok, <code>count</code> is increasing for <code>list</code> when I debug)</p>
  
  <p>Step.3 Repopulate the ListBox using my new 'list'. (Not Working)</p>
  
  <pre><code>&lt;div&gt;
  &lt;asp:ListBox ID="ListBox1" runat="server" Width="100%" Height="100%" AutoPostBack="true"/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Retrieve the file paths from database and populate DataTable: (This is ok)</p>
  
  <pre><code>private DataTable loadUserImageNames()
  {
      string cpUsersConnection1 = ConfigurationManager.ConnectionStrings["cp_usersConnection"].ToString();
      SqlConnection oSqlConnection1 = new SqlConnection(cpUsersConnection1);
      oSqlConnection1.Open();
      SqlCommand oSqlCommand1 = new SqlCommand();
      oSqlCommand1.Connection = oSqlConnection1;
      oSqlCommand1.CommandType = CommandType.Text;
      oSqlCommand1.CommandText = "SELECT FilePath from User_Images where AcNo ='" + AcNo.Text + "' ORDER BY AcNo";
      SqlDataAdapter oSqlDataAdapter1 = new SqlDataAdapter();
      oSqlDataAdapter1.SelectCommand = oSqlCommand1;
      DataTable oDataTable1 = new DataTable("User_Images");
      oSqlDataAdapter1.Fill(oDataTable1);
      return oDataTable1;
  }
  </code></pre>
  
  <p>Assign DataTable to Listbox (This is ok).</p>
  
  <p>Recall each item from ListBox and remove Path, leaving only <code>finalFileName</code> (This is ok).</p>
  
  <p>Assign <code>finalFileName</code> to <code>list</code> (I think this is ok, 'count' is increasing in debugging)</p>
  
  <p>Assign <code>list</code> to <code>ListBox1</code>....this is not working, ListBox1 is empty.</p>
  
  <pre><code>if (!Page.IsPostBack)
  {
      DataTable oDataTable1 = loadUserImageNames();
      ListBox1.DataSource = oDataTable1;
      ListBox1.DataTextField = "FilePath";
      ListBox1.DataBind();
  
      List&lt;string&gt; list = new List&lt;string&gt;();
  
      foreach (ListItem s in ListBox1.Items)
      {
          string filePath = (s.ToString());
          string finalFileName = (filePath.Substring(filePath.LastIndexOf('/') + 1));
          list.Add(finalFileName);
      }
      ListBox1.DataSource = list;
  }
  </code></pre>