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

Radcombobox Add Item with Value

1 Answer 392 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
niloofar
Top achievements
Rank 1
niloofar asked on 31 Jul 2011, 05:59 AM
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

1 Answer, 1 is accepted

Sort by
0
Thad
Top achievements
Rank 2
answered on 31 Jul 2011, 01:46 PM
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
Tags
ComboBox
Asked by
niloofar
Top achievements
Rank 1
Answers by
Thad
Top achievements
Rank 2
Share this question
or