Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态列表值 Dictionary employeeInfoList=new Dictionary(); employeeInfoList=EmployeeInfoProxy.GetAllEmployeeInfo(租户ID); 如果(employeeInfoList!=null) { List employee=新列表(employeeInfoList.Values); ViewData[“Name”]=员工[0]。姓名; ViewData[“工资”]=员工[0]。工资; ViewData[“部门”]=员工[0]。部门; ViewData[“指定”]=员工[0]。指定; ViewData[“地址”]=员工[0]。地址; ViewData[“Address1”]=员工[0]。地址1; }_C#_Asp.net - Fatal编程技术网

C# 动态列表值 Dictionary employeeInfoList=new Dictionary(); employeeInfoList=EmployeeInfoProxy.GetAllEmployeeInfo(租户ID); 如果(employeeInfoList!=null) { List employee=新列表(employeeInfoList.Values); ViewData[“Name”]=员工[0]。姓名; ViewData[“工资”]=员工[0]。工资; ViewData[“部门”]=员工[0]。部门; ViewData[“指定”]=员工[0]。指定; ViewData[“地址”]=员工[0]。地址; ViewData[“Address1”]=员工[0]。地址1; }

C# 动态列表值 Dictionary employeeInfoList=new Dictionary(); employeeInfoList=EmployeeInfoProxy.GetAllEmployeeInfo(租户ID); 如果(employeeInfoList!=null) { List employee=新列表(employeeInfoList.Values); ViewData[“Name”]=员工[0]。姓名; ViewData[“工资”]=员工[0]。工资; ViewData[“部门”]=员工[0]。部门; ViewData[“指定”]=员工[0]。指定; ViewData[“地址”]=员工[0]。地址; ViewData[“Address1”]=员工[0]。地址1; },c#,asp.net,C#,Asp.net,上面的代码工作正常。如果该员工只有一条记录,那么我就硬编码了employee[0] 如果有更多行,如何将这些索引传递给employee(例如employee[\i应该在此处动态获取值)。如果我正确理解您的问题,给定一个列表,您可以使用linq获取单个员工 Dictionary<string, EmployeeInfo> employeeInfoList = new Dictionary<string, EmployeeInfo>(); employeeInfoList

上面的代码工作正常。如果该员工只有一条记录,那么我就硬编码了
employee[0]


如果有更多行,如何将这些索引传递给employee(例如employee[\i应该在此处动态获取值)。

如果我正确理解您的问题,给定一个列表,您可以使用linq获取单个员工

Dictionary<string, EmployeeInfo> employeeInfoList = new Dictionary<string, EmployeeInfo>();

employeeInfoList = EmployeeInfoProxy.GetAllEmployeeInfo(TenantId);

if (employeeInfoList != null)
{
    List<EmployeeInfo> employee = new List<EmployeeInfo>(employeeInfoList.Values);

    ViewData["Name"] = employee[0].Name; 
    ViewData["Salary"] = employee[0].Salary;
    ViewData["Department"] = employee[0].Department;
    ViewData["Designation"] = employee[0].Designation;
    ViewData["Address"] = employee[0].Address;
    ViewData["Address1"] = employee[0].Address1;
}
也就是说,我不知道你是否有一个针对员工的“密钥”,比如Id或类似的

要通过索引获取,您有一个更大的往返行程(将员工输出到网格或类似的东西,允许单击传入您想要的员工的索引,并以这种方式访问单个eployee)

除非您在“EmployeeInfoProxy.GetAllEmployeeInfo()”方法中大量使用缓存,否则我会说您需要一个“GetEmployeeInfoById()”,我会再次强调,您的EmployeeInfo需要有一个具有某种描述的唯一Id,这会让您的生活变得更加轻松

希望这有帮助。 干杯 特里

[此外] 如果employeeListInfo有3个条目,那么要访问每个条目,我认为最好的方法是创建一个viewmodel(看起来这是MVC),但在最坏的情况下,您可以:

EmployeeInfo singleEmployee = employee.Where( x => x.Id).SingleOrDefault();
if (singleEmployee != null)
{
   do something here
}
List employee=新列表(employeeInfoList.Values);
ViewData[“员工”]=员工;
那么在你看来,只要做:

List<EmployeeInfo> employee = new List<EmployeeInfo>(employeeInfoList.Values);

ViewData["Employees"] = employee;


通过高亮显示代码并按101010,最好用代码标记将代码包围起来。现在,关于您的问题,您可以通过employeeInfoList进行查询。如果您不知道如何执行此操作,请在employeeInfoList中按此操作,我将返回三个计数employeeInfoList=EmployeeInfoProxy.GetAllEmployeeInfo(TenantId);但它只显示第一条记录如何进行二元分析?
<% foreach(EmployeeInfo employeeDetails in ViewData["Employees"] as List<EmployeeInfo>) { %>
   <!-- you will be looping through each employee here, so you can do as you wish
<% } %>