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

RadGrid binding with web service

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Piyush Bhatt
Top achievements
Rank 2
Piyush Bhatt asked on 09 Jan 2014, 06:18 PM
I have a sample program and trying to use the declarative binding using WCF service. It does not give error but only shows empty grid. it also shows the count but not the data. Data service returns data JSON data as well that I can see via browser developer tools.
            <ClientSettings>
                <ClientEvents OnDataBindingFailed="onError" />
                <DataBinding Location="DataService.svc"
                    SelectMethod="GetStatesForGrid"                    
                    DataPropertyName="Data"
                    FilterParameterType="Linq"
                    SortParameterType="Linq"></DataBinding>
            </ClientSettings>

Here is the service interface:
    [ServiceKnownType(typeof(State))]
    [ServiceContract]
    public interface IDataService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
        StateResult GetStatesForGrid(int startRowIndex, int maximumRows, string sortExpression, string filterExpression);

Here is the service code (this is just sample code, goal is not to actually try filtering paging etc, just to send data and see if it binds):

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class DataService : IDataService
    {
        public StateResult GetStatesForGrid(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
        {
            StateResult result = new StateResult();
            List<State> states = GetDataFromDb();
            result.Count = states.Count;
            result.Data = states;

            return result;
        }

If I use the ASMX service and call the same service method - it works fine. But not for WCF.

Another issue is, I tried calling the same method via PageMethod and use the .aspx page and method name in the declarative clientsettings - but that gives error that 'startIndex' not found.

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 14 Jan 2014, 12:34 PM
Hello,

The client-side binding configuration that you posted looks correct. Only thing is you do not need to set  DataPropertyName when binding to WCF services. Other than that the method should be called and return data. An online working example is also available here:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/declarative/defaultcs.aspx
You can use it as a starting point and modify it according to your needs.
Using page methods is not necessary here, because WCF biding should also work fine if you follow the approach in the demo.

Regards,
Marin
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Piyush Bhatt
Top achievements
Rank 2
Answers by
Marin
Telerik team
Share this question
or