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

Set a value while load on demand by web service

1 Answer 21 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nessi
Top achievements
Rank 1
Nessi asked on 01 Sep 2015, 06:42 PM

Hi!

I'm using multiple RadComboBoxes that are filled by a web service like this:

1.<telerik:RadComboBox runat="server" ID="Value" Width="300px" EnableLoadOnDemand="true" OnClientItemsRequesting="LookupItemRequesting" OnItemsRequested="Value_OnItemsRequested" AutoPostBack="False">
2.  <WebServiceSettings Path="/Handlers/IdmpService.asmx" Method="LoadDropDownValues" UseHttpGet="true"></WebServiceSettings>
3.</telerik:RadComboBox>

The method to fill the combobox looks like this:

01.[WebMethod(true)]
02.[ScriptMethod(UseHttpGet = true)]
03.public RadComboBoxData LoadDropDownValues(RadComboBoxContext context)
04.{
05.  var res = new RadComboBoxData();
06.  var itemType = context["ItemType"].AsString();
07.  var valueProperty = context["ValueProperty"].AsString();
08.  ...
09.  var result = new List<RadComboBoxItemData>();
10.  try
11.  {
12.    ...
13.    foreach (Dictionary<string, object> item in items)
14.    {
15.      // process items...
16.      result.Add(new RadComboBoxItemData { Value = "some integer id", Text = string.Join(", ", string.Format(displayFormat, values.ToArray())) });
17.    }
18.  }
19.  catch (Exception ex)
20.  {
21.    result = new List<RadComboBoxItemData> { new RadComboBoxItemData { Value = "", Text = ex.Message } };
22.  }
23.  res.Items = result.ToArray();
24.  return res;
25.}

Together with quite a few other Telerik controls this is a form used to view/edit data, so I need to set a specific value for thie ComboBox. How can I assign a value to the ComboBox to make sure that when I save the whole data, I can read the correct value from the ComboBox?

Thanks!

 

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 04 Sep 2015, 01:24 PM
Hello Nessi,

Could you please elaborate a bit more on your scenario, so we could suggest you the proper approach for your case. If you simply get some value, in order to set it as selected for the RadComboBox (that you have demonstrated above) you can use the set_text() on the control, as demonstrated below:

<script type="text/javascript">
           function OnClientLoad(sender) {
               sender.set_text("The Item To Select");
           }
       </script>


Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Nessi
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or