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

RadListBox.Items.Clear()

5 Answers 746 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Warren
Top achievements
Rank 1
Warren asked on 17 Jul 2009, 05:23 PM
I am using the Clear() method on the RadListBox items in an Update Panel.  The items are not being cleared from the list box when the method is called.  I'm also calling ClearSelection() on another list box to remove the item selections and this does not seem to be working either.  Both are callbacks in an UpdatePanel to an event being called on the server.

Warren

5 Answers, 1 is accepted

Sort by
0
Warren
Top achievements
Rank 1
answered on 17 Jul 2009, 07:34 PM
Sorry for the confusion.  The behavior I was seeing was caused by a problem I had with a postback trigger.  This issue was not in the list box itself.
0
Wendy Hunt
Top achievements
Rank 2
answered on 01 Feb 2010, 10:22 PM
I don't know if mine is postback trigger issue... but I'm having the same issue of it not clearing. 
My code for the control is
        this.selectedLocationsRadListBox.ClearSelection();  
        this.selectedRenewableSourceRadListBox.ClearSelection(); 
And it is being called by another method.  The other controls are working fine, but I can't get the destination boxes to clear out the old data.

Here is the whole file:
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
 
using Telerik.Web.UI;  
 
using TipData.BO;  
 
namespace Tip.Pages  
{  
    public partial class SOI : System.Web.UI.Page  
    {
      #region Private Variables  
 
      private TipData.BO.SOI soi;  
      private TipData.BO.Project project;  
      RadWindow window = new RadWindow();
      #endregion  
 
      #region Private Methods  
 
      private void ClearFields()  
      {  
        this.contractNameTextBox.Text = string.Empty;  
        this.descriptionTextBox.Text = string.Empty;  
        this.notesTextBox.Text = string.Empty;  
        this.participatingEntityTextBox.Text = string.Empty;  
 
        this.unredactedCheckBox.Checked = false;  
        this.supplDataProvideCheckBox.Checked = false;  
        this.redactedCheckBox.Checked = false;  
 
        this.requestingEntityRadComboBox.SelectedIndex = 0;  
        this.leadOrganizationRadComboBox.SelectedIndex = 0;  
        this.projectRadComboBox.SelectedIndex = 0;  
        this.tierRadComboBox.SelectedIndex = 0;  
 
        this.submitDateRadDatePicker.Clear();  
 
        this.availableLocationsRadListBox.SelectedIndex = 0;  
        this.availableRenewableSourceRadListBox.SelectedIndex = 0;  
 
        this.selectedLocationsRadListBox.ClearSelection();  
        this.selectedRenewableSourceRadListBox.ClearSelection();  
      }  
 
      private void DisableFields()  
      {  
        this.participatingEntityTextBox.Enabled = false;  
        this.contractNameTextBox.Enabled = false;  
        this.descriptionTextBox.Enabled = false;  
        this.notesTextBox.Enabled = false;  
            
        this.tierRadComboBox.Enabled = false;  
        this.leadOrganizationRadComboBox.Enabled = false;  
        this.projectRadComboBox.Enabled = false;  
        this.requestingEntityRadComboBox.Enabled = false;  
          
        this.submitDateRadDatePicker.Enabled = false;  
 
        this.availableLocationsRadListBox.Enabled = false;  
        this.availableRenewableSourceRadListBox.Enabled = false;  
        this.selectedLocationsRadListBox.Enabled = false;  
        this.selectedRenewableSourceRadListBox.Enabled = false;  
 
        this.unredactedCheckBox.Enabled = false;  
        this.supplDataProvideCheckBox.Enabled = false;  
        this.redactedCheckBox.Enabled = false;  
      }  
 
      private void EnableFields()  
      {  
        this.contractNameTextBox.Enabled = true;  
        this.descriptionTextBox.Enabled = true;  
        this.notesTextBox.Enabled = true;  
        this.participatingEntityTextBox.Enabled = true;  
 
        this.leadOrganizationRadComboBox.Enabled = true;  
        this.tierRadComboBox.Enabled = true;  
        this.projectRadComboBox.Enabled = true;  
        this.requestingEntityRadComboBox.Enabled = true;  
 
        this.submitDateRadDatePicker.Enabled = true;  
 
        this.availableLocationsRadListBox.Enabled = true;  
        this.availableRenewableSourceRadListBox.Enabled = true;  
        this.selectedLocationsRadListBox.Enabled = true;  
        this.selectedRenewableSourceRadListBox.Enabled = true;  
 
        this.unredactedCheckBox.Enabled = true;  
        this.supplDataProvideCheckBox.Enabled = true;  
        this.redactedCheckBox.Enabled = true;  
      }  
 
      private void PopulateComboBox()  
      {  
        IQueryable allLeadOrganization = Org.GetAllBindings();  
        this.leadOrganizationRadComboBox.DataSource = allLeadOrganization;  
        this.leadOrganizationRadComboBox.DataValueField = "ID";  
        this.leadOrganizationRadComboBox.DataTextField = "Name";  
        this.leadOrganizationRadComboBox.DataBind();  
        this.leadOrganizationRadComboBox.Filter = RadComboBoxFilter.Contains;  
 
        IQueryable allTier = Tier.GetAllBindings();  
        this.tierRadComboBox.DataSource = allTier;  
        this.tierRadComboBox.DataValueField = "ID";  
        this.tierRadComboBox.DataTextField = "Name";  
        this.tierRadComboBox.DataBind();  
        this.tierRadComboBox.Filter = RadComboBoxFilter.Contains;  
 
        IQueryable allRequestingEntities = TipData.BO.Entity.GetAllBindings(nullnull);  
        this.requestingEntityRadComboBox.DataSource = allRequestingEntities;  
        this.requestingEntityRadComboBox.DataValueField = "ID";  
        this.requestingEntityRadComboBox.DataTextField = "Name";  
        this.requestingEntityRadComboBox.DataBind();  
        this.requestingEntityRadComboBox.Filter = RadComboBoxFilter.Contains;  
      }  
 
      private void PopulateProject()  
      {  
        IQueryable allProjectName = Project.GetAllBindings(null);  
        this.projectRadComboBox.DataSource = allProjectName;  
        this.projectRadComboBox.DataValueField = "ID";  
        this.projectRadComboBox.DataTextField = "Name";  
        this.projectRadComboBox.DataBind();  
        this.projectRadComboBox.Filter = RadComboBoxFilter.Contains;  
        this.createNewProjectButton.Enabled = true;  
        this.projectRadComboBox.Enabled = true;  
      }  
 
      private void PopulateSOI()  
      {  
        if (soi != null)  
        {  
          this.contractNameTextBox.Text = soi.DataModel.ContactInfo;  
          this.descriptionTextBox.Text = soi.DataModel.Description;  
          this.notesTextBox.Text = soi.DataModel.Notes;  
          this.participatingEntityTextBox.Text = soi.DataModel.ParticipatingEntity;  
 
          this.submitDateRadDatePicker.SelectedDate = soi.DataModel.SubmittalDate;  
 
          this.tierRadComboBox.Text = Convert.ToString(soi.DataModel.Tier.Value);  
          this.leadOrganizationRadComboBox.Text = soi.DataModel.Org.Name;  
          this.requestingEntityRadComboBox.Text = Convert.ToString(soi.DataModel.Entity.Name);  
          this.projectRadComboBox.Text = Convert.ToString(project.DataModel.Name);   
 
          this.unredactedCheckBox.Checked = soi.DataModel.UnredactedFOIA;  
          this.supplDataProvideCheckBox.Checked = soi.DataModel.SupplierDataProvided;  
          this.redactedCheckBox.Checked = soi.DataModel.RedactedFOIA;  
 
          DisableButtons();  
          DisableFields();  
        }  
        else 
        {  
          // clear fields  
          EnableButtons();  
          EnableFields();  
        }  
 
      }  
 
      private void PopulateListBoxes()  
      {  
        IQueryable allAvailableLocations;  
        IQueryable allAvailableRenewableSources;  
 
        if (soi.DataModel == null)  
        {  
          allAvailableLocations = Location.GetAllBindings(null);  
          allAvailableRenewableSources = RenewableSource.GetAllBindings(null);  
        }  
        else 
        {  
          allAvailableLocations = Location.GetAllAvailableBindings(soi.DataModel.ID);  
          allAvailableRenewableSources = RenewableSource.GetAllAvailableBindings(soi.DataModel.ID);  
 
          IQueryable selectedLocations = Location.GetAllBindings(soi.DataModel.ID);  
          this.selectedLocationsRadListBox.DataSource = selectedLocations;  
          this.selectedLocationsRadListBox.DataValueField = "ID";  
          this.selectedLocationsRadListBox.DataTextField = "Name";  
          this.selectedLocationsRadListBox.DataBind();  
          this.selectedLocationsRadListBox.Sort = RadListBoxSort.Ascending;  
          this.selectedLocationsRadListBox.SortItems();  
 
          IQueryable selectedRenewableSources = RenewableSource.GetAllBindings(soi.DataModel.ID);  
          this.selectedRenewableSourceRadListBox.DataSource = selectedRenewableSources;  
          this.selectedRenewableSourceRadListBox.DataValueField = "ID";  
          this.selectedRenewableSourceRadListBox.DataTextField = "Name";  
          this.selectedRenewableSourceRadListBox.DataBind();  
          this.selectedRenewableSourceRadListBox.Sort = RadListBoxSort.Ascending;  
          this.selectedRenewableSourceRadListBox.SortItems();  
        }  
 
        this.availableLocationsRadListBox.DataSource = allAvailableLocations;  
        this.availableLocationsRadListBox.DataValueField = "ID";  
        this.availableLocationsRadListBox.DataTextField = "Name";  
        this.availableLocationsRadListBox.DataBind();  
        this.availableLocationsRadListBox.Sort = RadListBoxSort.Ascending;  
        this.availableLocationsRadListBox.SortItems();  
 
        this.availableRenewableSourceRadListBox.DataSource = allAvailableRenewableSources;  
        this.availableRenewableSourceRadListBox.DataValueField = "ID";  
        this.availableRenewableSourceRadListBox.DataTextField = "Name";  
        this.availableRenewableSourceRadListBox.DataBind();  
        this.availableRenewableSourceRadListBox.Sort = RadListBoxSort.Ascending;  
        this.availableRenewableSourceRadListBox.SortItems();  
      }  
 
      private void EnableButtons()  
      {  
        this.createNewProjectButton.Enabled = true;  
        this.createNewContactNameButton.Enabled = true;  
        this.createContractNumberButton.Enabled = true;  
        this.createNewRequestingEntityButton.Enabled = true;  
      }  
 
      private void DisableButtons()  
      {  
        this.createNewContactNameButton.Enabled = false;  
        this.createContractNumberButton.Enabled = false;  
        this.createNewRequestingEntityButton.Enabled = false;  
      }  
 
      private void PopulateRadWindow()  
      {  
        window.Behaviors = WindowBehaviors.Close;  
        window.Height = Unit.Pixel(300);  
        window.Width = Unit.Pixel(400);  
        window.VisibleStatusbar = false;  
        window.VisibleOnPageLoad = true;  
      }
      #endregion  
 
 
      #region Event Handlers  
      protected void Page_Load(object sender, EventArgs e)  
      {  
        soi = TipData.BO.SOI.Get(77);  
        project = TipData.BO.Project.Get(4);  
 
        if (!Page.IsPostBack)  
        {  
          PopulateListBoxes();  // leave here for the Ascending sort to work properly  
          PopulateComboBox();  
          PopulateSOI();  
          PopulateProject();  
        }  
        this.availableLocationsRadListBox.Transferred += new RadListBoxTransferredEventHandler(locationsRadListBox_Transferred);  
        this.availableRenewableSourceRadListBox.Transferred += new RadListBoxTransferredEventHandler(renewableSourceRadListBox_Transferred);  
      }  
 
      protected void newButton_Click(object sender, EventArgs e)  
      {  
        // create new SOI  
        soi = new TipData.BO.SOI();  
        ClearFields();  
        EnableButtons();  
        EnableFields();  
        // Rebind ListBoxes  
//        PopulateListBoxes();  (soi == null) not catching nulls  
 
        //put in PopulateListBoxes method  
        IQueryable allAvailableLocations;  
        IQueryable allAvailableRenewableSources;  
        allAvailableLocations = Location.GetAllBindings(null);  
        allAvailableRenewableSources = RenewableSource.GetAllBindings(null);  
        this.availableLocationsRadListBox.DataSource = allAvailableLocations;  
        this.availableLocationsRadListBox.DataValueField = "ID";  
        this.availableLocationsRadListBox.DataTextField = "Name";  
        this.availableLocationsRadListBox.DataBind();  
        this.availableLocationsRadListBox.Sort = RadListBoxSort.Ascending;  
        this.availableLocationsRadListBox.SortItems();  
 
        this.availableRenewableSourceRadListBox.DataSource = allAvailableRenewableSources;  
        this.availableRenewableSourceRadListBox.DataValueField = "ID";  
        this.availableRenewableSourceRadListBox.DataTextField = "Name";  
        this.availableRenewableSourceRadListBox.DataBind();  
        this.availableRenewableSourceRadListBox.Sort = RadListBoxSort.Ascending;  
        this.availableRenewableSourceRadListBox.SortItems();  
 
        this.editButton.Enabled = false;  
      }  
 
      protected void editButton_Click(object sender, EventArgs e)  
      {  
        EnableFields();  
        EnableButtons();  
      }  
 
      protected void saveButton_Click(object sender, EventArgs e)  
      {  
 
      }  
 
      protected void cancelButton_Click(object sender, EventArgs e)  
      {  
 
      }  
 
      protected void createNewProjectButton_Click(object sender, EventArgs e)  
      {  
        window.NavigateUrl = "CreateProjectDetail.aspx";  
        PopulateRadWindow();  
        RadWindowManager1.Windows.Add(window);  
      }  
 
      protected void createNewContactNameButton_Click(object sender, EventArgs e)  
      {  
 
      }  
 
      protected void createNewProjectGroupButton_Click(object sender, EventArgs e)  
      {  
        window.NavigateUrl = "CreateProjectGroupDetail.aspx";  
        PopulateRadWindow();  
        RadWindowManager1.Windows.Add(window);  
      }  
 
      protected virtual void locationsRadListBox_Transferred(object sender, RadListBoxTransferredEventArgs e)  
      {  
        this.availableLocationsRadListBox.Sort = RadListBoxSort.Ascending;  
        this.availableLocationsRadListBox.SortItems();  
      }  
 
      protected virtual void renewableSourceRadListBox_Transferred(object sender, RadListBoxTransferredEventArgs e)  
      {  
        this.availableRenewableSourceRadListBox.Sort = RadListBoxSort.Ascending;  
        this.availableRenewableSourceRadListBox.SortItems();  
      }  
 
      protected void projectRadComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)  
      {  
        PopulateProject();  
      }  
 
      protected void createNewRequestingEntityButton_Click(object sender, EventArgs e)  
      {  
        window.NavigateUrl = "CreateRequestingEntityDetail.aspx";  
        PopulateRadWindow();  
        RadWindowManager1.Windows.Add(window);  
      }  
 
      protected void createNewContactNameButton_Click1(object sender, EventArgs e)  
      {  
        window.NavigateUrl = "CreateContactDetail.aspx";  
        PopulateRadWindow();  
        RadWindowManager1.Windows.Add(window);  
      }  
        
      protected void createContractNumberButton_Click(object sender, EventArgs e)  
      {  
 
      }
      #endregion  
    }  
}  
 

Thanks in advance for any help.  :)
0
Genady Sergeev
Telerik team
answered on 05 Feb 2010, 10:09 AM
Hello Wendy Hunt,

I cant see anything wrong in your codebehind. Please, make sure that the ListBox you are trying to clear is correctly updated if it is update panel. Do you use UpdatePanel or RadAjaxPanel?

Kind regards,
Genady Sergeev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Wendy Hunt
Top achievements
Rank 2
answered on 05 Feb 2010, 03:43 PM
It is in an UpdatePanel.  Are there properties that need to be set that would affect this?

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
      <ContentTemplate> 
...  
 <!------------- LOCATIONS LIST BOX --------------------------------->    
        <asp:Label ID="Label11" runat="server" Text="Locations:" 
          style="z-index:1; position:absolute; top:275px; left:67px; text-align: right;"></asp:Label> 
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"   
          style="z-index:1; position:absolute; top:275px; left:150px; height: 78px; width: 75px;">  
          <telerik:RadListBox ID="availableLocationsRadListBox" runat="server" Height="125px"   
                Width="150px"   
                AutoPostBackOnTransfer="true" 
                AllowTransfer="true" 
                TransferToID="selectedLocationsRadListBox"   
                Skin="WebBlue"   
                SelectionMode="Multiple">   
          </telerik:RadListBox> 
        </telerik:RadAjaxPanel>    
        <telerik:RadListBox runat="server" ID="selectedLocationsRadListBox" Height="125px" Width="100px" 
          style="z-index:1; position:absolute; top:275px; left:300px;"  /> 
        
    <!------------- RENEWABLE SOURCE LIST BOX ------------------------------->    
        <asp:Label ID="Label12" runat="server" Text="Renewable Source:" 
          style="z-index:1; position:absolute; top:407px; left:13px; width: 127px; text-align: right;"></asp:Label> 
        <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server"   
          style="z-index:1; position:absolute; top:407px; left:150px; height: 78px; width: 75px;"   
          EnableTheming="True">  
          <telerik:RadListBox ID="availableRenewableSourceRadListBox" runat="server" Height="125px"   
                Width="150px"   
                AllowTransfer="true"   
                TransferToID="selectedRenewableSourceRadListBox" 
                Skin="WebBlue"   
                AutoPostBackOnTransfer="true" 
                SelectionMode="Multiple">  
          </telerik:RadListBox> 
        </telerik:RadAjaxPanel> 
        <telerik:RadListBox runat="server" ID="selectedRenewableSourceRadListBox" Height="125px" Width="100px" 
          style="z-index:1; position:absolute; top:407px; left:300px;"  /> 
...  
 
      </ContentTemplate> 
    </asp:UpdatePanel> 
 

Let me know if you see anything in this code sample that would need altering.  Thanks! 

Should I put in a ticket?

wen
0
Genady Sergeev
Telerik team
answered on 11 Feb 2010, 09:05 AM
Hi Wendy Hunt,

You need not to nest RadAjaxPanels inside UpdatePanels, in fact this seems to be the reason for the problems your experience. Please, remove the two RadAjaxPanels that are inside the update panel or Remove the UpdatePanel and make sure that both the source and the destination listbox are under the very same RadAjaxPanel.

All the best,
Genady Sergeev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
ListBox
Asked by
Warren
Top achievements
Rank 1
Answers by
Warren
Top achievements
Rank 1
Wendy Hunt
Top achievements
Rank 2
Genady Sergeev
Telerik team
Share this question
or