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

Binding to ASMX always empty

4 Answers 66 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 25 Jun 2014, 07:25 PM
Hi,

I am trying to bind a simple RadListView using a WebService (ASMX).

Here is my code:
<telerik:RadListView runat="server" ID="lvTest">
    <ClientSettings>
        <DataBinding>
            <ItemTemplate>
                <div class="item">
                    #= Text#
                </div>
            </ItemTemplate>
            <EmptyDataTemplate>
                <div>No items</div>
            </EmptyDataTemplate>
            <DataService Location="~/Code/GenericHandlers/TestWS.asmx" DataPropertyName="Data" CountPropertyName="Count"
                DataPath="GetData" SortParameterType="Linq" FilterParameterType="Linq" />
        </DataBinding>
    </ClientSettings>
</telerik:RadListView>

Here is my TestWS.asmx (Json() simply convert the object to a Json string using the JavascriptSerializer):
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class TestWS
    Inherits System.Web.Services.WebService
 
    <WebMethod()> _
    Public Function GetData() As String
        Return Json(New With {Key .Data = New Temp() {New Temp("Item1"), New Temp("Item2")}, .Count = 2})
    End Function
 
End Class
 
Public Class Temp
    Private _text As String
 
    Public Property Text() As String
        Get
            Return _text
        End Get
        Set(ByVal value As String)
            _text = value
        End Set
    End Property
 
    Public Sub New(ByVal pText As String)
        _text = pText
    End Sub
End Class

When I run the page, I can see in the Chrome debugger that GetData is correctly called and return this: 
{"d":"{\"Data\":[{\"Text\":\"Item1\"},{\"Text\":\"Item2\"}],\"Count\":2}"}

But I can't understand why the ListView is still empty and don't show the data.

What did I miss there?

Jocelyn

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2014, 11:39 AM
Hi Jocelyn,

Please take a look into the ListView - Web Service Binding online demo and this help documentation for more information on how to configure the control in this case.

Thanks,
Shinu.
0
Jocelyn
Top achievements
Rank 1
answered on 26 Jun 2014, 01:42 PM
Hi Shinu,

I already looked at this help documentation and online demo. This is why I am posting here because it still doesn't work.

This should be correctly coufigured because the ListView retrieve the Data from my asmx, but it doesn't to BIND it to the ListView.

Thanks
0
Accepted
Marin
Telerik team
answered on 01 Jul 2014, 08:39 AM
Hello Jocelyn,

In order to correctly databind the RadListView the web service has to return data in JSON format. The returned data in your case is string which causes the problem:
"d":"{\"Data\":[{\"Text\":\"Item1\"},{\"Text\":\"Item2\"}],\"Count\":2}"
Additionally you also need a Layout template and an item placeholder where the ListView will render the data items (as shown in the demo)

With this the correct setup of the RadListView and the asmx web service will look like this:
<WebMethod> _
<ScriptMethod(ResponseFormat := ResponseFormat.Json)> _
Public Function GetData() As List(Of Temp)
    Dim list = New List(Of Temp)()
    list.Add(New Temp("Item1"))
    list.Add(New Temp("Item2"))
    Return list
End Function

<telerik:RadListView runat="server" ID="lvTest">
                <LayoutTemplate>
                    <div id="items">
                    </div>
                </LayoutTemplate>
                <ClientSettings>
                    <DataBinding ItemPlaceHolderID="items">
                        <ItemTemplate>
                            <div class="item">
                                #= Text#
                            </div>
                        </ItemTemplate>
                        <EmptyDataTemplate>
                            <div>No items</div>
                        </EmptyDataTemplate>
                        <DataService Location="TestWS.asmx" DataPath="GetData" />
                    </DataBinding>
                </ClientSettings>
            </telerik:RadListView>



Regards,
Marin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jocelyn
Top achievements
Rank 1
answered on 02 Jul 2014, 02:44 PM
Hi Marin,

Thanks for your help!

This is what I was missing:
<ScriptMethod(ResponseFormat := ResponseFormat.Json)> _

Regards,
Jocelyn
Tags
ListView
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Marin
Telerik team
Share this question
or