More in this section
Forums / Developing with Sitefinity / listbox in createusercontrol - how to

listbox in createusercontrol - how to

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 1 answered
  1. gus
    gus avatar
    4 posts
    10 Aug 2009
    18 Aug 2009
    Link to this post
    How can I add a listbox, and populate with 3 items in the createusercontrolwizard?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    19 Aug 2009
    Link to this post
    Hello gus,

    You can add the control declaratively

            <asp:ListBox ID="lb1" runat="server" > 
            <asp:ListItem Text="test1"></asp:ListItem> 
            <asp:ListItem Text="test2"></asp:ListItem> 
            <asp:ListItem Text="test3"></asp:ListItem> 

    or bind the control to a datasource

      private string ConnectionString() 
            return System.Configuration.ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString; 
        private void BindListBox() 
            DataTable table = new DataTable(); 
            SqlConnection connection = new SqlConnection(ConnectionString()); 
                string sqlStatement = "SELECT Top(5)* FROM telerik_Users"
                SqlCommand command = new SqlCommand(sqlStatement, connection); 
                SqlDataAdapter sqlData = new SqlDataAdapter(command); 
                if (table.Rows.Count > 0) 
                    lb1.DataSource = table; 
                    lb1.DataTextField = "UserName"
                    lb1.DataValueField = "UserId"
            catch (System.Data.SqlClient.SqlException ex) 
                string msg = "Error"
                msg += ex.Message; 
                throw new Exception(msg); 

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 1 answered