Cannot bind ListView to web service.

4 posts, 0 answers
  1. Rod
    Rod avatar
    2 posts
    Member since:
    Sep 2012

    Posted 13 Mar 2012 Link to this post

    I have been trying many ways to bind the listview to an ASP.Net .asmx web service. I have attached the code for both the consuming page and the web service.

    I have tried many different ways to return the data from the web service and event tried to just return a string array. The listview works if you bind it to the static flatData var.

    Any help or examples would be great!

    R

    Client side:

    </

     

    head>

    <

     

    body>

    <form id="form1" runat="server">

    <div data-role="layout" data-id="mxl" data-platform="ios">

    <div data-role="header">

    MobileXus Header

    </div>

    <div data-role="footer">

    iOS MobileXus Footer

    </div>

    </div>

    <div data-role="view" id="flat" data-init="mobileListViewDataBindInitFlat" data-title="ListView" data-layout="mxl">

    <ul id="listview">

    </ul>

    </div>

    <script type="text/javascript">

     

    var flatData = ["Sashimi salad", "Chirashi sushi", "Seaweed salad", "Edamame"];

    function mobileListViewDataBindInitFlat() {

    $(

    "#listview").kendoMobileListView({ dataSource: flatData });

    }

    var deviceJDS = new kendo.data.DataSource({

    transport: {

    read: {

    contentType:

    "application/json; charset=utf-8",

    type:

    "POST",

    data:

    "{}",

    dataType:

    "json",

    url:

    "WebServices/TestService.asmx/GetList"

    }

    }

    });

    var app = new kendo.mobile.Application();

    </script>

    </form>

    </

     

    body>

    </

     

    html>



    Web service:

    ///

     

    <summary>

    ///

     

    Summary description for TestService

    ///

     

    </summary>

    [

    WebService(Namespace = "http://tempuri.org/")]

    [

    WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

    [System.Web.Script.Services.

    ScriptService]

    public

     

    class TestService : System.Web.Services.WebService {

    public TestService () {

    //Uncomment the following line if using designed components

    //InitializeComponent();

    }

    [

    WebMethod]

    [

    ScriptMethod(ResponseFormat = ResponseFormat.Json)]

    public Array GetList() {

    DeviceSvc.

    Device dsvc = new DeviceSvc.Device();

    DeviceSvc.

    Device1[] devices = null;

    ArrayList devlist = new ArrayList();

    devices = dsvc.SelectAll();

    foreach (DeviceSvc.Device1 d in devices)

    {

    devlist.Add(d.Name);

    }

    string[] data = { "Rod", "Karen", "Jamie", "Christopher" };

    return data;

    }

    }

  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 15 Mar 2012 Link to this post

    Hello Rod,

    ASMX services return JSON in the following format { "d": <result> }, for that reason it is necessary to define the data function of the schema. For example:
    var deviceJDS = new kendo.data.DataSource({
        transport: {
            read: {
                contentType: "application/json; charset=utf-8",
                type: "POST",
                data: "{}",
                dataType: "json",
                url: "WebServices/TestService.asmx/GetList"
            }
        },
        schema: {
            data: "d" //Specify how to get the result.
        }
    });

    I hope this information will help you to solve the problem.

    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Rod
    Rod avatar
    2 posts
    Member since:
    Sep 2012

    Posted 16 Mar 2012 Link to this post

    Ok, I have the web service returning the data now but the mobile list view is displaying it as [object Object] instead of the data. Any ideas on what may be going on?
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 19 Mar 2012 Link to this post

    Hi Rod,

    The problem might appear if the model of the schema is not defined in the correct way. Please check the network requests with Firebug or Chrome Developer Tools and confirm the model configuration.

    For convenience I am attaching a sample project that shows ListView binding to web service. I hope this example will help you to solve the issue.

    Greetings,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready