我正在使用 WCF 服务将数据显示到 gridview 中,但显示不正确(列显示无序)
以下是我的单独类文件,其中包含要添加到 IList 对象代码的属性:
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; }
}
}
这是服务接口
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();
}
}
这是使用 System 实现 IService.cs Service1 的服务类;使用 System.Collections.Generic;使用 System.Linq;使用 System.Runtime.Serialization;使用 System.ServiceModel;使用 System.ServiceModel.Web;使用 System.Text;使用 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;
}
}
}
下面是我的消费者代码,它有一个 gridview 数据绑定控件。和消费者代码
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();
}