GridView data binding in ASP.NET using WCF service

By | May 16, 2012

In this article I will explain how to bind data in a GridView from SQL Server database using a WCF Service

Introduction

In this article first we will create a WCF service to get data from a SQL Server table. Then we will bind these data in a GridView control.

Step 1:

Create a new WCF Service Application

Note: I am using Microsoft Visual Web Developer 2010 Express

Step 2:

Add following code in IService1.cs

Step 3:

Add following code in Service1.svc.cs

Note: Add your connection string in the Web.config file

Step 4:

Run the application to open WCF Test Client

Copy the path of Service1.svc

Step 5:

We have created a WCF service to retrieve data from database. Now we will create an ASP.NET Web Application and add drag a GridView control on Default.aspx as below

Step 6:

  • Add WCF service reference in the project
  • Right click on Service References in Solution Explorer
  • Select Add Service Reference
  • Paste location of Service1.svc in the Address box copied in Step 4
  • Click on Go
  • Click on OK

Step 7:

Add following code in Default.aspx.cs

Final Output:

0 thoughts on “GridView data binding in ASP.NET using WCF service

  1. net grid

    Thanks DEEPAK you are decribes very well article .its very helpful for me dapfor. com

    Reply
  2. sourabh

    Dera sir, i am getting this error Employee:interfaces cannot declare types

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *