Radcombobox Add Item with Value

2 posts, 0 answers
  1. niloofar
    niloofar avatar
    58 posts
    Member since:
    Aug 2010

    Posted 31 Jul 2011 Link to this post

    hi
    i use these codes for fill combobox
    //Item Request

     

    protected void Customer_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
           {
               LoadCustomerData();
               (o as RadComboBox).Items.Clear();
               string text = e.Text;
               try
               {
                   DataRow[] rows = CustomerData.Select("title LIKE '" + text + "*'");
                   int itemsPerRequest = 20;
                   int itemOffset = e.NumberOfItems;
                   int endOffset = itemOffset + itemsPerRequest;
                   if (endOffset > rows.Length)
                   {
                       endOffset = rows.Length;
                   }
                   for (int i = itemOffset; i < endOffset; i++)
                   {
                       (o as RadComboBox).Items.Add(new RadComboBoxItem(rows[i]["title"].ToString()));
                   }
                   e.Message = String.Format("رکورد <b>1</b>-<b>{0}</b> از <b>{1}</b> رکورد", endOffset.ToString(), rows.Length.ToString());
               }
               catch { }
           }

     

    ********************************************************************************

     

     

    private void LoadCustomerData()
            {
                if (Cache["CustomerData"] == null)
                {
                    DataTable words = new DataTable("words");
                    DataColumn title = words.Columns.Add("title");
                    DataColumn id = words.Columns.Add("id");
                    string word = String.Empty;
                    List<CDS.IAS.Logic.Sale.User.NameResult> result = CDS.IAS.Logic.Sale.Customer.Customer.GetCustomerName();
                    foreach (var item in result)
                    {
                        words.Rows.Add(item.FullName, item.ID);
                    }
      
                    Cache["CustomerData"] = words;
                }
      
                CustomerData = (DataTable)Cache["CustomerData"];
            }

    ********************************************************************************
    and in page load:

    if (!IsPostBack)

    { 

    LoadCustomerData();

    }
    i just set Item but i need to insert value
    beacuse i use to my program this code:combobox.selected value
    please help to me
    thanks a lot

  2. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 31 Jul 2011 Link to this post

    Hi Niloofar,

    It looks like you are missing adding your cached id  value to the RadComboBox. 

    Try changing this code:
    for (int i = itemOffset; i < endOffset; i++)
    {
        (o as RadComboBox).Items.Add(new RadComboBoxItem(rows[i]["title"].ToString()));
    }

    to this:
    for (int i = itemOffset; i < endOffset; i++)
    {
        (o as RadComboBox).Items.Add(new RadComboBoxItem(
            rows[i]["title"].ToString(),
            rows[i]["id"].ToString() ));
    }

    Hope that helps,
    Thad
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top