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

Cannot bind ListView to web service.

3 Answers 193 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 13 Mar 2012, 03:28 PM
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;

}

}

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Mar 2012, 02:56 PM
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!
0
Rod
Top achievements
Rank 1
answered on 16 Mar 2012, 10:40 AM
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?
0
Alexander Valchev
Telerik team
answered on 19 Mar 2012, 02:44 PM
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!
Tags
ListView (Mobile)
Asked by
Rod
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Rod
Top achievements
Rank 1
Share this question
or