On ItemsRequested event - do not update other controls

2 posts, 0 answers
  1. Kaushal
    Kaushal avatar
    8 posts
    Member since:
    Mar 2012

    Posted 12 Jun 2012 Link to this post

    I have a combobox and it fires event onItemsRequested. In the code, I bring some class objects and convert them to table and bind with combobox. So far so good. but when the data returned is zero then I want to show error message on the screen that combobox is empty because of the errorr... I update the label (id = lblError) during the code i.e. lblError.Text = "blah bla blah...." but it does not get updated on the screeen. I have ajaxmanager on the aspx page and lblError is included under the ajax settings. so I basically I want to update the label during Combobox_ItemRequested event.

      RadComboBox rcb = (RadComboBox)sender;
     rcb.ClearSelection();
     rcb.Text = string.Empty;
      rcb.Items.Clear();
      rcb.ShowMoreResultsBox = false;
      rcb.BackColor = System.Drawing.Color.Empty;
      
     Employee[] lemployee = Employee.Search();
      
                                if (lemployee.Length == 0)
                                {
                                    lblError.Text = "No employee found";
                                    return;
                                }
                                else
                                {
                                    lblError.Text = "";
                                     
                                    DataTable dtable = new DataTable();
                                    DataRow orow;
      
                                    dtable.Columns.Add("empID");
                                    dtable.Columns.Add("name");
                                    dtable.Columns.Add("SortFlag");
                                    dtable.Columns.Add("Address");
      
                                    foreach (Employee oemp  in lEmployee)
                                    {
                                        orow = dtable.NewRow();
      
                                        orow["empID"] = oemp.empId.ToString();
                                        orow["name"] = oemp.name.Trim();
                                        orow["Address"] = oemp.Address;
                                        orow["SortFlag"] = "2";
      
                                        dtable.Rows.Add(orow);
                                    }
      
                                    rcb.DataSource = dtable;
                                    rcb.DataBind();
    }


  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 18 Jun 2012 Link to this post

    Hi Kaushal,

    I am afraid that by design the ItemsRequested event handler can be used only for providing data to populate the RadComboBox with items and is not intended to be used for updating other controls.

    However you can use the RadComboBoxItemsRequestedEventArgs to provide a status message.
    Please take a look at this online demo and the GetStatusMessage method implementation there.

    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top