将值添加到网格视图 [英] Adding values to grid view
本文介绍了将值添加到网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我已经创建了一个Web服务,它从我的客户端表中返回所有客户端的客户端名称和ID。
现在我添加了服务的引用我的网络应用程序。
现在我想在我的应用程序的网格视图中返回客户端名称和客户端ID。
任何人都可以帮助。
以下是我的代码:
Imyservice
[ServiceContract]
public interface Imyservice
{
[OperationContract]
List< ClientDetails> getClient();
}
myservice.cs
public class myservice:Imyservice
{
public 列表< ClientDetails> getClient()
{
List< ClientDetails> client = new List< ClientDetails>();
SysXAppDBEntities app = new SysXAppDBEntities();
var sql =(来自 pro in app.Clients
选择 new ClientDetails()
{
ClientID = pro.ClientID,
ClientName = pro.ClientName
});
return sql.ToList();
}
}
ClientDetails:
[DataContract]
public class ClientDetails
{
[DataMember]
public string ClientName
{
get ;
set ;
}
[DataMember]
public Int32 ClientID
{
get ;
set ;
}
[DataMember]
public Int32 TenantID
{
get ;
set ;
}
}
解决方案
找到解决方案:
protected void Page_Load( object sender,EventArgs e)
{
ServiceReference1.ImyserviceClient svc = new ServiceReference1.ImyserviceClient();
IList< clientdetails> customers = svc.getClient();
GridView1.DataSource = customers;
GridView1.DataBind();
}
< / clientdetails > 跨度>
hi
I have made a web service which returns client name and id of all the clients from my client table.
now i have added reference of the service in my web application.
now i want to return client name and client id in the grid view in my application.
can anyone help.
below is my code:
Imyservice
[ServiceContract]
public interface Imyservice
{
[OperationContract]
List<ClientDetails> getClient();
}
myservice.cs
public class myservice : Imyservice
{
public List<ClientDetails> getClient()
{
List<ClientDetails> client = new List<ClientDetails>();
SysXAppDBEntities app = new SysXAppDBEntities();
var sql = (from pro in app.Clients
select new ClientDetails()
{
ClientID = pro.ClientID,
ClientName = pro.ClientName
});
return sql.ToList();
}
}
ClientDetails :
[DataContract]
public class ClientDetails
{
[DataMember]
public string ClientName
{
get;
set;
}
[DataMember]
public Int32 ClientID
{
get;
set;
}
[DataMember]
public Int32 TenantID
{
get;
set;
}
}
解决方案
found the solution:
protected void Page_Load(object sender, EventArgs e) { ServiceReference1.ImyserviceClient svc = new ServiceReference1.ImyserviceClient(); IList<clientdetails> customers = svc.getClient(); GridView1.DataSource = customers; GridView1.DataBind(); } </clientdetails>
这篇关于将值添加到网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文