Radcombobx Problem

3 posts, 0 answers
  1. Manish
    Manish avatar
    4 posts
    Member since:
    Sep 2010

    Posted 19 Nov 2010 Link to this post

    Hi Team Telerik,

    I am Using RadCombobx as a filter under the Rad Grid. Herein i am populating the data by using the Web service., now I want to add alternate colors to the each item inside the rad combo box. But I am not getting it on any of the Client Side event specially i tried on Client-Load event. but not succeeded yet.

    Please can you quote something on this.

    Also I want to know is there any other method for multiselection of radcombobox  other than Checkbox Method.

    Thanking you in anticipation,
    Fast response is highly appreciable.

    With Regards,
    Manish
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Nov 2010 Link to this post

    Hello Manish,
    You can use the following Javascript to set different colors to the ComboBox items.

    JavaScript:
    function OnClientLoad(sender, args)
         {
            var combo = sender;
            items = combo.get_items();
            for (i = 0; i < items.get_count(); i++)
            {
                var comboItem = items.getItem(i);
                if (i % 2 == 0)
                {
                    comboItem._element.style.color = "green";
                }
                else
                    comboItem._element.style.color = "Red";
             }
          }

    You can make use of the property AutoCompleteSeparator to achieve your second requirement.Please go through the following document for more information.
    ComboBox / Autocomplete
    -Shinu.
  3. Manish
    Manish avatar
    4 posts
    Member since:
    Sep 2010

    Posted 20 Nov 2010 Link to this post

    Hi Shinu,

    Thanks for the fast response.

        But this trick not solve my problem yet. It reflect changes, if I used am previously filling radcombobx but in case of the "Autocomplete" feature It is not changing the the background color as well as font color.  

    In autocomplete thing I am using Web-Service. Where in I am filling the data in the combobox by using RadComboBoxData to return the results

    This is code where i am getting data from
    I need to make alternate colors to the items


     [System.Web.Services.WebMethod]
        public RadComboBoxData GetName(RadComboBoxContext context)
        {
            try
            {
                int ItemsPerRequest = 10;

                DataSet ds = new DataSet();
                string parameter;
                parameter = context.Text + "%";
             
                string sql = "SELECT DISTINCT(BillToFirstName + ', ' + BillToLastName) as Name FROM ac_Orders Where ((BillToFirstName + ', ' + BillToLastName) like '" + parameter + "')  AND OrderStatusId <>7";
                SqlDataAdapter da = new SqlDataAdapter(sql, ConnString);
             
                da.Fill(ds, "ac_Orders");

                RadComboBoxData comboData = new RadComboBoxData();
                int itemOffset = context.NumberOfItems;
                int endOffset = Math.Min(itemOffset + ItemsPerRequest, ds.Tables[0].Rows.Count);
                comboData.EndOfItems = endOffset == ds.Tables[0].Rows.Count;

                List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset);

                for (int i = itemOffset; i < endOffset; i++)
                {
                    RadComboBoxItemData itemData = new RadComboBoxItemData();
                    itemData.Text = ds.Tables[0].Rows[i]["Name"].ToString();
                    itemData.Value = ds.Tables[0].Rows[i]["Name"].ToString();

                    result.Add(itemData);
                }

                comboData.Items = result.ToArray();
                return comboData;
            }
            catch (Exception ex)
            {
                throw;
            }
        }


Back to Top