Radlistview and webservice.asmx

13 posts, 0 answers
  1. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 07 Mar 2013 Link to this post

    hi guys,

    ì wrote this web service code:
    Imports System.Web.Services
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Web.Script.Services
    Imports System
    Imports System.Data
    Imports System.Web
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI
    <WebService([Namespace]:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ScriptService()> _
    Public Class TryWebService
    <WebMethod()> _
    Public Function Search(ByVal _Str1 As String, ByVal _Str2 As String) As List(Of PropertyUtente)
    Using scope As New TransactionScope()
    Dim lista As New List(Of PropertyUtente)
    Dim conString = ConfigurationManager.ConnectionStrings("TrycontactString")
    Dim strConnString As String = conString.ConnectionString
    Using db As New SqlConnection(strConnString)
    db.Open()
    Using sqlcmd As New SqlCommand("Sp_searching_like", db)
    sqlcmd.CommandType = CommandType.StoredProcedure
    sqlcmd.Parameters.AddWithValue("@Search", SqlDbType.VarChar).Value = _Str1
    sqlcmd.Parameters.AddWithValue("@Searchluogo", SqlDbType.VarChar).Value = _Str2
    Using sqldr As SqlDataReader = sqlcmd.ExecuteReader
    While sqldr.Read
    Dim _image As String
    If sqldr.GetSqlString(6).IsNull = True Then
    _image = "/image/avatarborder.png"
    Else
    _image = sqldr.GetSqlString(6).Value
    End If
    Dim recapiti As String = ""
    If (sqldr.GetSqlValue(4).IsNull = True Or sqldr.GetSqlValue(4).ToString = String.Empty) And (sqldr.GetSqlValue(5).IsNull = True Or sqldr.GetSqlValue(5).ToString = String.Empty) Then
    recapiti = "Non disponile"
    ElseIf sqldr.GetSqlValue(4).IsNull = False And (sqldr.GetSqlValue(5).IsNull = True Or sqldr.GetSqlValue(5).ToString = String.Empty) Then
    recapiti = sqldr.GetSqlValue(4).Value
    ElseIf (sqldr.GetSqlValue(4).IsNull = True Or sqldr.GetSqlValue(4).ToString = String.Empty) And (sqldr.GetSqlValue(5).IsNull = False) Then
    recapiti = sqldr.GetSqlValue(5).Value
    ElseIf sqldr.GetSqlValue(4).IsNull = False And sqldr.GetSqlValue(5).IsNull = False Then
    recapiti = sqldr.GetSqlValue(4).Value & " - " & sqldr.GetSqlValue(5).Value
    End If
    lista.Add(New PropertyUtente With {.idutente = sqldr.GetSqlInt32(0).Value, _
    .utente = sqldr.GetSqlString(1).Value, _
    .Desccategoria = sqldr.GetSqlString(2).Value, _
    .Desccomune = sqldr.GetSqlString(3).Value, _
    .Telefono = recapiti, _
    .Imageprofile = _image, _
    .Email = sqldr.GetSqlString(7).Value})
    End While
    End Using
    End Using
    End Using
    Return lista
    scope.Complete()
    End Using
    End Function
    End Class

    and this is radlistview html code:

    <telerik:RadListView ID="RadListView1" runat="server" DataKeyNames="idutente"
                               ItemPlaceholderID="Contenitore" AllowPaging="True"
                               Width="650px">
                                   <LayoutTemplate>
                                       <fieldset style="width: 700px; border:0px" id="FieldSet1">
                                           <legend></legend>
                                           <asp:Panel ID="Contenitore" runat="server">
                                           </asp:Panel>
                                           <telerik:RadDataPager ID="RadDataPager1" runat="server"
                                               PagedControlID="RadListView1" Width="700px" Culture="it-IT" BackColor ="#ecede5">
                                                   <Fields>
                                                       <telerik:RadDataPagerButtonField FieldType="FirstPrev"></telerik:RadDataPagerButtonField>
                                                       <telerik:RadDataPagerButtonField FieldType="Numeric"></telerik:RadDataPagerButtonField>
                                                       <telerik:RadDataPagerButtonField FieldType="NextLast"></telerik:RadDataPagerButtonField>
                                                   </Fields>
                                           </telerik:RadDataPager>
                                       </fieldset>
                                   </LayoutTemplate>
                                   <ItemTemplate>
                                       <div class="item">
                                           <div class="image">
                                               <asp:Image ID="Image1" runat="server" ImageUrl='<%# CType(Container.DataItem, PropertyUtente).imageprofile%>' Height="120px" Width="110px"/>
                                           </div>
                                       <div class="content">
                                           <div class="user">
                                               <div style="width:16px; height:16px; float:left; padding-right:3px">
                                                   <img src="/image/icone/user1.png" alt="NP" />
                                               </div>
                                               <b><%# CType(Container.DataItem, PropertyUtente).utente%></b>
                                           </div>
                                           <div class="description_category">
                                               <div style="width:16px; height:16px; float:left; padding-right:3px">
                                                   <img src="/image/icone/categoria.png" alt="NP" />
                                               </div> Categoria: <%# CType(Container.DataItem, PropertyUtente).Desccategoria%>
                                           </div>
                                           <div class="description_city">
                                               <div style="width:16px; height:16px; float:left; padding-right:3px">
                                                   <img src="/image/icone/home.png" alt="NP" />
                                               </div> Città: <%# CType(Container.DataItem, PropertyUtente).Desccomune%></div>
                                           <div class="description_email">
                                               <div style="width:16px; height:16px; float:left; padding-right:3px">
                                                   <img src="/image/icone/email.png" alt="NP" />
                                               </div> Email: <%# CType(Container.DataItem, PropertyUtente).Email%>
                                           </div>                                             
                                           <div class="description_phone">
                                               <div style="width:16px; height:16px; float:left; padding-right:3px">
                                                   <img src="/image/icone/telefono.png" alt="NP" />
                                               </div>Telefono: <%# CType(Container.DataItem, PropertyUtente).Telefono%></div>                                   
                                           <div class="item_button">
                                               <telerik:RadButton ID="RadButton1" runat="server" Text="Biglietto completo" Width="140px" Skin="Office2010Silver"
                                               OnClick="RadButton1_Click">
                                               </telerik:RadButton>
                                           </div>                                                                              
                                       </div>
                                       </div>
                                   </ItemTemplate>
                           </telerik:RadListView>


    this code is possible send it to source radlistview?

  2. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 12 Mar 2013 Link to this post

    Hi,

     You can check out the web service binding demo and help topic in the RadListView for more information on how to configure the control in this case.

    Kind regards,
    Marin
    the Telerik team
    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 their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 12 Mar 2013 Link to this post

    Why use this code: SortParameterType="Linq" FilterParameterType="Linq" ?
  5. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 13 Mar 2013 Link to this post

    Hi,
    I can not understand the help that you have sent, please I have this my webservice, how do I connect it to radlistview?

    <%@ WebService Language="vb" CodeBehind="~/App_Code/TryWebService.vb" Class="TryWebService" %>

    Imports System.Web.Services
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Web.Script.Services
    Imports System
    Imports System.Data
    Imports System.Web
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI
    Imports System.Transactions
    <WebService([Namespace]:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ScriptService()> _
    Public Class TryWebService
        <WebMethod()> _
        Public Function Search(ByVal _Str1 As String, ByVal _Str2 As String) As List(Of PropertyUtente)
            Using scope As New TransactionScope()
                Dim lista As New List(Of PropertyUtente)
                Dim conString = ConfigurationManager.ConnectionStrings("TrycontactString")
                Dim strConnString As String = conString.ConnectionString
                Using db As New SqlConnection(strConnString)
                    db.Open()
                    Using sqlcmd As New SqlCommand("Sp_searching_like", db)
                        sqlcmd.CommandType = CommandType.StoredProcedure
                        sqlcmd.Parameters.AddWithValue("@Search", SqlDbType.VarChar).Value = _Str1
                        sqlcmd.Parameters.AddWithValue("@Searchluogo", SqlDbType.VarChar).Value = _Str2
                        Using sqldr As SqlDataReader = sqlcmd.ExecuteReader
                            While sqldr.Read
                                Dim _image As String
                                If sqldr.GetSqlString(6).IsNull = True Then
                                    _image = "/image/avatarborder.png"
                                Else
                                    _image = sqldr.GetSqlString(6).Value
                                End If
                                Dim recapiti As String = ""
                                If (sqldr.GetSqlValue(4).IsNull = True Or sqldr.GetSqlValue(4).ToString = String.Empty) And (sqldr.GetSqlValue(5).IsNull = True Or sqldr.GetSqlValue(5).ToString = String.Empty) Then
                                    recapiti = "Non disponile"
                                ElseIf sqldr.GetSqlValue(4).IsNull = False And (sqldr.GetSqlValue(5).IsNull = True Or sqldr.GetSqlValue(5).ToString = String.Empty) Then
                                    recapiti = sqldr.GetSqlValue(4).Value
                                ElseIf (sqldr.GetSqlValue(4).IsNull = True Or sqldr.GetSqlValue(4).ToString = String.Empty) And (sqldr.GetSqlValue(5).IsNull = False) Then
                                    recapiti = sqldr.GetSqlValue(5).Value
                                ElseIf sqldr.GetSqlValue(4).IsNull = False And sqldr.GetSqlValue(5).IsNull = False Then
                                    recapiti = sqldr.GetSqlValue(4).Value & " - " & sqldr.GetSqlValue(5).Value
                                End If
                                lista.Add(New PropertyUtente With {.idutente = sqldr.GetSqlInt32(0).Value, _
                                                                    .utente = sqldr.GetSqlString(1).Value, _
                                                                    .Desccategoria = sqldr.GetSqlString(2).Value, _
                                                                    .Desccomune = sqldr.GetSqlString(3).Value, _
                                                                    .Telefono = recapiti, _
                                                                    .Imageprofile = _image, _
                                                                    .Email = sqldr.GetSqlString(7).Value})
                            End While
                        End Using
                    End Using
                End Using
                Return lista
                scope.Complete()
            End Using
        End Function
    End Class
  6. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 14 Mar 2013 Link to this post

    Hello,

     You can connect the ListView to the web service by using the DataBinding settings as shown in the demo and help topic that I sent:

    <DataService Location="~/Services/GridWcfService.svc"
                             DataPath="GetDataAndCount"
                             SortParameterType="Linq"
                             FilterParameterType="Linq" />

    The sort and filter parameter are set to Linq according to how you need the ListView to construct the data query with the respective parameters passed to the service via json. The default value for the parameters is List. 

    Kind regards,
    Marin
    the Telerik team
    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 their blog feed now.
  7. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 14 Mar 2013 Link to this post

    ok,
    but i wrote this:

    <telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True"
        DataKeyNames="idutente" PageSize="8"
        Width="700px">
        <ClientSettings>
          <DataBinding ItemPlaceHolderID="Contenitore">
            <LayoutTemplate>
                <fieldset style="width: 700px; border:0px; background-color: #FFFFFF; background-image: none;" id="FieldSet1">
                    <div id="Contenitore" runat="server">
                    </div>
                </fieldset>
            </LayoutTemplate>
            <ItemTemplate>
                <div class="item-sponsor">
                  <span class="name">#= utente #</span>
                <span class="company">#= desccategoria #</span>                                                                                                              
                </div>
            </ItemTemplate>
            <DataService Location="WebService.asmx" DataPath="RandomCard"></DataService>
        </DataBinding>
    </ClientSettings>
    </telerik:RadListView>


    and  this:

    <WebMethod()> _
    Public Function RandomCard() As List(Of PropertyUtente)
        Using scope As New TransactionScope()
            Dim lista As New List(Of PropertyUtente)
     
            Dim conString = ConfigurationManager.ConnectionStrings("TrycontactString")
            Dim strConnString As String = conString.ConnectionString
            Using db As New SqlConnection(strConnString)
                db.Open()
                Using sqlcmd As New SqlCommand("Sp_RandomCard", db)
                    sqlcmd.CommandType = CommandType.StoredProcedure
                    Using sqldr As SqlDataReader = sqlcmd.ExecuteReader
                        While sqldr.Read
                            Dim _image As String
                            If sqldr.GetSqlString(3).IsNull = True Then
                                _image = "/image/avatarborder.png"
                            Else
                                _image = sqldr.GetSqlString(3).Value
                            End If
                            lista.Add(New PropertyUtente With {.idutente = sqldr.GetSqlInt32(0).Value, _
                                                                .utente = sqldr.GetSqlString(1).Value, _
                                                                .Desccategoria = sqldr.GetSqlString(2).Value, _
                                                                .Imageprofile = _image})
                        End While
                    End Using
                End Using
            End Using
            Return lista
            scope.Complete()
        End Using
    End Function

    the function is executed but no data is displayed in the listview
  8. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 14 Mar 2013 Link to this post

    Hi,

     The setup of the ListView looks properly configured. You can check whether the RandomCard method returns actual list of some object and whether any of the objects in the list has the same utente and desccategoria properties (including lower / upper case) so that they are correctly serialized on the client and shown in the ListView.

    Regards,
    Marin
    the Telerik team
    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 their blog feed now.
  9. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 15 Mar 2013 Link to this post

    Please help me...now i wrote this code
    <telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True"
        DataKeyNames="idutente" ItemPlaceholderID="Contenitore" PageSize="8"
        Width="700px" OnNeedDataSource="RadListView1_NeedDataSource">
            <LayoutTemplate>
                <fieldset style="width: 700px; border:0px; background-color: #FFFFFF; background-image: none;" id="FieldSet1">
                    <div id="Contenitore" runat="server">
                    </div>
                </fieldset>
            </LayoutTemplate>
            <ItemTemplate>
                <div class="item-sponsor">
                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# CType(Container.DataItem, PropertyUtente).imageprofile%>' CssClass="img"/>
                    <span class="name"> <%# CType(Container.DataItem, PropertyUtente).utente%> </span>
                    <span class="title"> <%# CType(Container.DataItem, PropertyUtente).Desccategoria%></span>                                                                                                                                                             
                </div>
            </ItemTemplate>
    </telerik:RadListView>

    because i dont know to connect this webservice to radlistview:

    <WebMethod()> _
    Public Function RandomCard() As List(Of PropertyUtente)
        Using scope As New TransactionScope()
            Dim lista As New List(Of PropertyUtente)
     
            Dim conString = ConfigurationManager.ConnectionStrings("TrycontactString")
            Dim strConnString As String = conString.ConnectionString
            Using db As New SqlConnection(strConnString)
                db.Open()
                Using sqlcmd As New SqlCommand("Sp_RandomCard", db)
                    sqlcmd.CommandType = CommandType.StoredProcedure
                    Using sqldr As SqlDataReader = sqlcmd.ExecuteReader
                        While sqldr.Read
                            Dim _image As String
                            If sqldr.GetSqlString(3).IsNull = True Then
                                _image = "/image/avatarborder.png"
                            Else
                                _image = sqldr.GetSqlString(3).Value
                            End If
                            lista.Add(New PropertyUtente With {.idutente = sqldr.GetSqlInt32(0).Value, _
                                                                .utente = sqldr.GetSqlString(1).Value, _
                                                                .Desccategoria = sqldr.GetSqlString(2).Value, _
                                                                .Imageprofile = _image})
                        End While
                    End Using
                End Using
            End Using
            Return lista
            scope.Complete()
        End Using
    End Function

    Imports System
    Imports System.Web
    Imports System.Collections
    Public Class PropertyUtente
        Public Property idutente As Integer
        Public Property utente As String
        Public Property Desccategoria As String
        Public Property Imageprofile As String
    End Class


    please Can you show me you as i must  connect the webservice to radlistview, using my code?

  10. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 20 Mar 2013 Link to this post

    Hi,

     I am attaching a sample page showing how to cofigure the web service binding in the ListView based on the code that you provided. The pages are standalone so you just need to add them to a web site and run it to check how it works.

    I hope this helps.

    Kind regards,
    Marin
    the Telerik team
    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 their blog feed now.
  11. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 20 Mar 2013 Link to this post

    ok thanks I will try that your code, but a question, with radlistview webservice and I am forced to use the following manufacturer parameters: SortParameterType = "Linq" FilterParameterType = "Linq"? That is, I use to manage the data from the database linq? I can not even write this code only in aspx? <DataService Location="~/TestVBService.asmx" DataPath="RandomCard"/>

    and another question...is faster pass data with OnNeedDataSource or with the webservice?
  12. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 21 Mar 2013 Link to this post

    Hi,

     The type of the parameter does not enforce specific usage of framework or technology to process the data in the service. It is used to determine the format of the sort and filter parameters when serialized and passed to the web service. Because different types of web services require different formats in order for the operations to be carried out successfully. If you do not specify parameter types the control will use the default value which is "List" and pass the values as simple array. It depends how you expect the parameters on the server-side end when handled by the service. You can check if it is appropriate to process them as simple arrays and properly construct the sort / filter query then you can stay with the default value. It is basically a choice of what suits bets your preferences.  More information on this can be found in the following help topic:
    http://www.telerik.com/help/aspnet-ajax/listview-clientside-sorting-filtering.html

    As for the speed of the data retrieving it depends a lot on where exactly the data server is located. Normally web services are used in case of a remote data and common disadvantage in this case is the network latency. However if you are querying a local data base in the same network then both methods will retrieve the data relatively for the same time. In case of web service you utilize the client-side binding features of the control without the need of postback and server-side processing which improves the user experience.

    Regards,
    Marin
    the Telerik team
    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 their blog feed now.
  13. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 21 Mar 2013 Link to this post

    Thanks for the response, as regards Support Department web, such as by code posted above, the step at radlistview a listoff, and this list is loaded with data from a query sql and not link. Now not having paramtri linq linq to not use technology as potri pass data to the list radlistview? I tried to write like this:
    aspx code:
    <ClientSettings>
    <DataBinding ItemPlaceHolderID="Contenitore">
    <ItemTemplate>
    <div class="myclass">
    <span>#= utente #</span>
    <span>#= Desccategoria #</span>
    </div>
    </ItemTemplate>
    <DataService Location="~/WebService.asmx" DataPath="RandomCard"/>
    </DataBinding>
    </ClientSettings>

    vb net code:
    Imports System.Web.Services
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Web.Script.Services
    Imports System
    Imports System.Data
    Imports System.Web
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI
    Imports System.Transactions
    <WebService([Namespace]:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ScriptService()> _
    Public Class TryWebService
        <WebMethod()> _
        Public Function RandomCard() As List(Of PropertyUtente)
            Using scope As New TransactionScope()
                Dim lista As New List(Of PropertyUtente)
     
                Dim conString = ConfigurationManager.ConnectionStrings("TrycontactString")
                Dim strConnString As String = conString.ConnectionString
                Using db As New SqlConnection(strConnString)
                    db.Open()
                    Using sqlcmd As New SqlCommand("Sp_RandomCard", db)
                        sqlcmd.CommandType = CommandType.StoredProcedure
                        Using sqldr As SqlDataReader = sqlcmd.ExecuteReader
                            While sqldr.Read
                                Dim _image As String
                                If sqldr.GetSqlString(3).IsNull = True Then
                                    _image = "/image/avatarborder.png"
                                Else
                                    _image = sqldr.GetSqlString(3).Value
                                End If
                                lista.Add(New PropertyUtente With {.idutente = sqldr.GetSqlInt32(0).Value, _
                                                                    .utente = sqldr.GetSqlString(1).Value, _
                                                                    .Desccategoria = sqldr.GetSqlString(2).Value, _
                                                                    .Imageprofile = _image})
                            End While
                        End Using
                    End Using
                End Using
                Return lista
                scope.Complete()
            End Using
        End Function
    End Class
     
    Public Class PropertyUtente
        Public Property idutente As Integer
        Public Property utente As String
        Public Property Desccategoria As String
        Public Property Imageprofile As String
    End Class


    sql code:
    SELECT TOP 8 u.id,u.utente,ca.descrizione as categoria,u.Imageprofile
    from  tab_utenti u
          inner join
          tab_categorie ca
          on u.idcategoria=ca.id ORDER BY NEWID()
    END

    but when I load the page the radlistview is empty.

    For the second argument that speed, you're right that depends on the network where you can find both the data server that the web server. In my case, the database and the web pages are on the same network ... So if I understand in this case, the speed of loading of the data is the same
  14. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 21 Mar 2013 Link to this post

    Hello,

     The code looks properly configured. You can try to debug it and place a breakpoint in the RandomCard method to see if it gets hit. If the method is not called you can also inspect whether there are any network errors during the call to the web service (for example FireBug in FireFox shows network errors in the Net tab).
    You can also use the attached example from my previous as a starting point which should work properly in this case.

    Greetings,
    Marin
    the Telerik team
    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 their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017