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

Telerik ComboBox get_items().add(item) not binding value at server

1 Answer 199 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
naman
Top achievements
Rank 1
naman asked on 29 Sep 2020, 11:31 AM
As i'm binding value in client site for combobox like this way in Jquery.

$.each(response, function (index, value) {
let item = new Telerik.Web.UI.RadComboBoxItem();
item.set_text(value.EnggName);
item.set_value(value.EngineerId);
$find('<%= cmb_EnggList.ClientID%>').get_items().add(item);
});

and it binds the value correctly but when i post it in the server like this.

foreach (Telerik.Web.UI.RadComboBoxItem EngineerId in cmb_EnggList.Items)// it gives empty items
{
  if (EngineerId.Checked)
  {
       Guid GuidEngineerId = new Guid(EngineerId.Value);
      _JobCalendarEngg = new JobCalendarEngg();
      _JobCalendarEngg.JobCalendarEnggId = Guid.NewGuid();
      _JobCalendarEngg.JobCalendarId = JobCalendarId;
      _JobCalendarEngg.EngineerId = GuidEngineerId;
      en.JobCalendarEnggs.Add(_JobCalendarEngg);
  }
}
It gives me empty 
cmb_EnggList.Items
 but when i bind it like this.

cmb_EnggList.Items.Clear();
foreach (var record in records)
{
   var EnggName = (from k in en.EngineersLibraries
   where k.EngineerId == record.EngineerId select k).FirstOrDefault(); Telerik.Web.UI.RadComboBoxItem item = new
   Telerik.Web.UI.RadComboBoxItem(EnggName.EngineerName, EnggName.EngineerId.ToString());
   cmb_EnggList.Items.Add(item);
}

And post it will give me binded value so in the whole scenario if i bind my drop down in Jquery it binds value in the client page and after post method it gives me an empty list but when i bind the drop down in my server end and when i post it will get me the binded list.
So i require my Jquery binded value to be get in my server list. f
oreach (Telerik.Web.UI.RadComboBoxItem EngineerId in cmb_EnggList.Items)

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 02 Oct 2020, 09:06 AM

Hi Naman,

In order to access any changes performed client-side at the server, you will need to you need to call the trackChanges() and commitChanges() client methods of RadComboBox, see Accessing Client Changes at the Server.

You can also check out the approach shown in the Add Item section in our Working with Items in Client-Side article:

function addNewItem() {
    var combo = $find("<%= RadComboBox1.ClientID %>");
    var comboItem = new Telerik.Web.UI.RadComboBoxItem();
    comboItem.set_text("New Item");
    combo.trackChanges();
    combo.get_items().add(comboItem);
    comboItem.select();
    combo.commitChanges();        
}
I hope this will prove helpful. Please let me know if any questions come up!

Kind regards,
Doncho
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
ComboBox
Asked by
naman
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or