I am using WCF service to display data into gridview but it not properly displaying(Columns are displaying out of order)
Following is my seperate class file containing properties to be added to IList object Code:
Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ServiceTest
{
public class Class1
{
public int index { get; set; }
public string name { get; set; }
public int id { get; set; }
}
}
This is Service interface
IService1.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Collections;
namespace ServiceTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
IList<Class1> GetD();
}
}
This is service class that implements IService.cs Service1 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Collections;
namespace ServiceTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public IList<Class1> GetD()
{
IList<Class1> lst = new List<Class1>();
for (int i = 0; i < 50; i++)
{
Class1 c = new Class1();
c.index = i;
c.name = "Madhavi " + i;
c.id = i + 1;
lst.Add(c);
}
return lst;
}
}
}
Below is my consumer code having one gridview databound control. And consumer code
protected void Page_Load(object sender, EventArgs e)
{
//IList i = new ArrayList();
Service1Client s = new Service1Client();
// i = s.GetD();
GridView1.DataSource = s.GetD();
GridView1.DataBind();
}
IList
.When you add reference of your service did you configure service return typeList
by default it isArray
– Neeraj Dubey