C# 使用.Net Web服务列表函数

C# 使用.Net Web服务列表函数,c#,asp.net,web-services,C#,Asp.net,Web Services,我正在尝试从web方法返回列表。 我正在尝试使用该服务,我遇到了问题。 我想在3个不同的标签上显示这些值,我不知道该怎么做 给定以下web方法: [WebMethod] public List<Employee> empWeb(int Id) { Employee emp = new Employee(); List<Employee> emplist = new List<Employee>();

我正在尝试从web方法返回列表。 我正在尝试使用该服务,我遇到了问题。 我想在3个不同的标签上显示这些值,我不知道该怎么做

给定以下web方法:

    [WebMethod]
    public List<Employee> empWeb(int Id)
    {
        Employee emp = new Employee();
        List<Employee> emplist = new List<Employee>();

        con.Open();
        SqlCommand cmd = new SqlCommand("select Id,FirstName,Salary from Emp where Id='" + Id + "' ", con);
        SqlDataReader dr;
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {

            emp.Id = Convert.ToInt32(dr["Id"]);
            emp.Name = dr["FirstName"].ToString();
            emp.Salary = Convert.ToInt32(dr["Salary"]);


        }

        con.Close();
        emplist.Add(emp);
        return emplist;
    }
现在我正在尝试在我的aspx页面中消费。我的aspx页面代码如下:-

    public void GetWebEmp()
{
    localhost.Service1 obj = new localhost.Service1();
    var lstwebemp = obj.empWeb(1);

}
在这个函数中,我想显示如下值

Label1.Text=Emp.Id

Label2.Text=Emp.Name

Label3.Text=Emp.Salary
但它在
lstwebemp
请帮忙

Label1.Text=lstwebemp[0].Id.ToString();

Label2.Text=lstwebemp[0].Name.ToString();

Label3.Text= lstwebemp[0].Salary.ToString();

找到解决方案了吗

        foreach (var emp in lstwebemp)
    {
        lbl1.Text =Convert.ToString(emp.Id);
        lbl2.Text = Convert.ToString(emp.Name);
        lbl3.Text = Convert.ToString(emp.Salary);

    }

谢谢,但它不起作用。lstwebemp“Id”未出现后,Suraj-我怀疑您需要一个ToString(),代码给出错误:'System.Array'不包含'Id'的定义,并且找不到接受'System.Array'类型的第一个参数的扩展方法'Id'(您是否缺少using指令或程序集引用?)@SurajSingh在标签中显示“localhost.Employee”,当我放入lstwebemp[1]时,它给出了错误索引Range@rahulaggrawal您能否检查此语句中的lstwebemp值
var lstwebemp=obj.empWeb(1)@SurajSingh在lstwebemp中有Id、Name和salary的所有值检查更新的代码。
Check if you are able to access properties like this .
        foreach (var emp in lstwebemp)
    {
        lbl1.Text =Convert.ToString(emp.Id);
        lbl2.Text = Convert.ToString(emp.Name);
        lbl3.Text = Convert.ToString(emp.Salary);

    }