RadListBox getting Selected Items server side

3 posts, 0 answers
  1. Steve
    Steve avatar
    9 posts
    Member since:
    Jun 2011

    Posted 26 Jul 2011 Link to this post

    I need to move selected items from a RadList box to two other listboxes depending upon which button a user clicks. I cannot use the built-in TransferToID because that will only handle one source and one target.

    The RadListBox get populated with a databind on the first load ...

    if (!Page.IsPostBack)

    {

        RadListBox1.DataSource = dt;

        RadListBox1.DataValueField = "UserID";

        RadListBox1.DataTextField ="FullName";

         RadListBox1.DataBind();

    }

     
    When I try accessing the selected items during a button-click event I do NOT get any hits ... nothing shows up in the SelectedItems collection of the RadListBox.  How can I solve this problem ? 

    Thanks.




    protected void btnFindSelected_Click(object sender, EventArgs e)

    {
    StringBuilder sb = new StringBuilder();


    foreach
    (RadListBoxItem item in RadListBox1.SelectedItems)  
    {

        sb.Append(item.Text);

            // THIS IS ALWAYS EMPTY NO MATTER HOW MANY ITEMS I SEE ON THE PAGE THAT AREA SELECTED
    }

     

     

    for (int i = 0; i < RadListBox1.Items.Count; i++)

    {

    if (RadListBox1.Items[i].Selected)

        {

        sb.Append(RadListBox1.Items[i].Text);

        }

     }

    }

    string thisList = sb.ToString();  
    // THIS IS ALWAYS EMPTY NO MATTER HOW MANY ITEMS I SEE ON THE PAGE THAT ARE SELECTED

     

     

     

     NOTE:  I was able to get a similar version of this to work successfully in a new project ... so there must be something else affecting the original that I haven't spotted.

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 29 Jul 2011 Link to this post

    Hi Steve,

    I've tried the provided code in a sample project and it works fine. It seems that there is something on your page that is clearing the selection of RadListBox. Is the latter dynamically loaded? Perhaps attaching your page here will shed some light on what is going wrong.

    Greetings,
    Genady Sergeev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steve
    Steve avatar
    9 posts
    Member since:
    Jun 2011

    Posted 29 Jul 2011 Link to this post

    I figured it out.  The method that populated the RadListBox was being called during a postback thus causing the RadListBox to get a new copy of the data.  What confused me was that visually the selected items were still displaying as selected. I moved the step to only load the data on initial page load and everything works fine.

    thanks
Back to Top