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

Can't Get Value Using Web Service

1 Answer 65 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
kencox
Top achievements
Rank 1
kencox asked on 06 Sep 2013, 06:36 PM
I'm adapting the load on demand from web service example. I'm adding an ID property and trying get the current/selected value (not the text!) from the combobox. It doesn't seem to be there.

I've pasted in the code so far. Could someone tell me what I'm doing wrong that the ID never shows up when calling get_value()?

using System.Collections;
using System.Collections.Generic;
using System.Web.Script.Services;
using System.Web.Services;
using Telerik.Web.UI;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ComboBoxWebService : WebService
{
    [WebMethod]
    public IEnumerable GetItems(RadComboBoxContext context)
    {
        RadComboBoxData result = new RadComboBoxData();
        int numberOfItems = (int)(context["ItemsCount"] ?? 1000);
        List<ComboBoxItemData> items = new List<ComboBoxItemData>();
        for (int i = 0; i < numberOfItems; i++)
        {
            ComboBoxItemData itemData = new ComboBoxItemData();
            itemData.Text = "Item " + i;
            itemData.ID = i;
            items.Add(itemData);
        }
        return items;
    }
 
}
public class ComboBoxItemData
{
    private string text;
    private int id;
    public string Text
    {
        get { return text; }
        set { text = value; }
    }
    public int ID
    {
        get { return id; }
        set { id = value; }
    }
}




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="DefaultCS" %>
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
 
        <div>
            <label>Number of items to load:</label>
 
            <asp:ScriptManager runat="server"></asp:ScriptManager>
            <telerik:RadNumericTextBox runat="server" ID="ItemsCountTextBox" Width="60"
                Value="1000" MaxValue="4000" MinValue="100" ShowSpinButtons="True">
                <NumberFormat DecimalDigits="0" />
            </telerik:RadNumericTextBox>
            <telerik:RadComboBox runat="server" ID="RadComboBox1" Width="240" Height="200px"
                DataTextField="Text" DataValueField="id" OnClientItemsRequested="OnClientItemsRequested"
                OnClientItemsRequesting="OnClientItemsRequesting" AppendDataBoundItems="true"
                EnableLoadOnDemand="true" EnableItemCaching="true">
                <ExpandAnimation Type="none" />
                <CollapseAnimation Type="none" />
                <WebServiceSettings Path="ComboBoxWebService.asmx" Method="GetItems" />
            </telerik:RadComboBox>
            <telerik:RadScriptBlock runat="Server" ID="RadScriptBlock1">
                <script type="text/javascript">
                    var startTime;
                    var sendRequest = true;
                    var calculate = false;
 
                    function OnClientItemsRequesting(sender, args) {
                        var input = $find("<%= ItemsCountTextBox.ClientID %>");
                        args.get_context()["ItemsCount"] = input.get_value();
                        startTime = new Date();
                    }
                    function OnClientItemsRequested(sender, args) {
                        var endTime = new Date();
                        //         $get("total").innerHTML = endTime - startTime + "ms";
                    }
 
                    function OnClientDropDownClosed(sender, args) {
                        sender.clearItems();
                        if (args.get_domEvent().stopPropagation)
                            args.get_domEvent().stopPropagation();
                    }
 
                    function GetCurrentValue(sender, args) {
                        var combo = $find("<%= RadComboBox1.ClientID %>");
                       alert(combo.get_value());
              }
                </script>
            </telerik:RadScriptBlock>
            <telerik:RadButton ID="btnSelect" runat="server" Text="Select" OnClientClicked="GetCurrentValue">
            </telerik:RadButton>
        </div>
    </form>
</body>
</html>

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 11 Sep 2013, 01:59 PM
Hi Ken,

 
Thank you for contacting Telerik support.

Here is the code that I changed at my side with the code that you shared in order to show the selected in RadComboBox text:

function GetCurrentValue(sender, args) {
                      var combo = $find("<%= RadComboBox1.ClientID %>");
                      alert(combo.get_selectedItem().get_text());
                  }

Hope this will be helpful. if you have further questions please don't hesitate to contact us again.

Regards,
Plamen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
ComboBox
Asked by
kencox
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or