ListBox.Items only returns the first

3 posts, 0 answers
  1. Pedro
    Pedro avatar
    4 posts
    Member since:
    Oct 2014

    Posted 23 Jan Link to this post

    Hi, I have a RadListBox that is being populated on Page_Load through a DataTable that comes from the DB. Problem is: when I try to iterate the ItemCollection (via the Items Property) the List has Count=1 (the first item), when it was supposed to be 20+(I don't know the exact item count). Below are the relevant snippets:

    Here the list is iterated to find out what items are selected in the db and move them from this list to another.

    protected void ListaPaisExp_ItemDataBound(object sender, RadListBoxItemEventArgs e)
            {
                foreach (DataRow dr in Empresa.Tables[1].Rows)
                {
                    foreach (RadListBoxItem item in ListaPaisExp.Items)
                    {
                        if (item.Value == dr["tipopaisid"].ToString())
                        {
                            ListaPaisExpSel.Items.Add(item);
                            item.Remove();
                        }
                    }
                }
            }

     

    And this is the DataBind on Page_Load:

    ListaPaisExp.DataSource = Tipos_DAL.GetTiposByArchtype("pais");
    ListaPaisExp.DataValueField = "ID";
    ListaPaisExp.DataTextField = "Descricao";
    ListaPaisExp.DataBind();
  2. Nencho
    Admin
    Nencho avatar
    1540 posts

    Posted 26 Jan Link to this post

    Hello Pedro,

    I am not quite sure about the logic implemented in the ItemDataBound event handler that you demonstrate. Please note that this event is triggered for each item from the datasource of the RadListBox.

    With that said, as I can see, you iterate trough a table content and in some cases you remove the items that the DataBound event is triggered for.

    Please described in details your business logic that needs to be implemented with the RadListBoxes so we could attempt to suggest you the proper implementation.

    Regards,
    Nencho
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Pedro
    Pedro avatar
    4 posts
    Member since:
    Oct 2014

    Posted 26 Jan Link to this post

    Ah, I wasn't aware that the event was triggered on every single item, so probably I will play around with the events to see which ones fits the bill.

    Regardless of that, my point with that code was to iterate the bound ListBox, and "move" (remove from one list and add to the other) the items selected in the DB to to the a second (empty and not bound) ListBox so that when this logic is done I have the add-able items on the first list and the existing items on the second list.

Back to Top