This is a migrated thread and some comments may be shown as answers.

RadListBox getting Selected Items server side

2 Answers 428 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 26 Jul 2011, 05:04 PM

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 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 29 Jul 2011, 11:46 AM
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.

0
Steve
Top achievements
Rank 1
answered on 29 Jul 2011, 03:38 PM
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
Tags
ListBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Steve
Top achievements
Rank 1
Share this question
or