private void PopulateContactList() { SqlConnection myCon = new SqlConnection(CON_STR); // SqlCommand myRequest = new SqlCommand("select * from contact order by Lastname", myCon SqlCommand myRequest = new SqlCommand("select * from AddContactCard order by Lastname", myCon); ContentPlaceHolder CPHMain = Page.Master.FindControl("CPHMain") as ContentPlaceHolder; try { myCon.Open(); SqlDataReader myReader = myRequest.ExecuteReader(); while (myReader.Read()) { //ListItem tmpItem = new ListItem(myReader["Firstname"].ToString() + " " + myReader["Lastname"].ToString(), myReader["CID"].ToString()); //LBoxContact.Items.Add(tmpItem); // Create instance of the UserControl SimpleControl WebUserControl1 contactCard = new WebUserControl1(); //Add the SimpleControl to Placeholder contactCard.addContactCard(myReader["Firstname"].ToString(), myReader["Lastname"].ToString(), myReader["Type"].ToString(), myReader["Phonenumber"].ToString(), myReader["Image"].ToString(), myReader["CID"].ToString()); CPHMain.Controls.Add(contactCard); } } catch (Exception ex) { Response.Write($"<script>alert('{ex.Message}');</script>"); } finally { myCon.Close(); } }