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

Using a Web Service to populate RadGrid

1 Answer 326 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paulo
Top achievements
Rank 1
Paulo asked on 11 Aug 2011, 05:58 PM

Hello.

In order to familiarize with the RadGrid component, I have created a small application whose grid is populated by a web service.

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
  
        <telerik:RadGrid ID="RadGrid1" runat="server">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" DataType="System.Int32" />
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" DataType="System.String" />
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <DataBinding Location="WebService.cs" SelectMethod="RetrieveRows" />
            </ClientSettings>
        </telerik:RadGrid>
    </form>   
</body>
</html>

WebService.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using Telerik.Web.UI;
  
namespace WebApplication1
{
    [ServiceContract(Namespace = "")]
    [System.Web.Script.Services.ScriptService]
    public class WebService
    {
        public WebService () 
        {
        }
   
        [OperationContract]
        public Dictionary<string, object> RetrieveRows(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression)
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            dictionary.Add("Data", new[] { new { ID = 1234, Name = "Test" }});
            dictionary.Add("Count", 1);
            return dictionary;
        }
    }
}

The compilation was successful, but the following error message was displayed at runtime by the built-in script debugger of Internet Explorer:
Line: 6563
Error: Sys.ArgumentException: Cannot deserialize empty string.
Parameter name: data

I would appreciate whether some assistance could be provided to solve this problem.

Last but not least:
a) I was wondering how the application could be implemented using a server-side binding solution.
b) What is Telerik's recommendation in regard to client versus server-side binding implementations using a web service?

Thank you in advance.
Paulo

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Aug 2011, 04:45 AM
Hello Paulo,

Please take a look at the following documentation and demo which explains the same.
Client-side Binding.
Grid / Programmatic Binding

Thanks,
Shinu.
Tags
Grid
Asked by
Paulo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or