我在ASP.net页面的网格视图中有一个员工数组列表,如下所示:
ArrayList tempempList = new ArrayList();
List<Employee> emps = new List<Employee>();
for (int i = 0; i < gvemp.Rows.Count; i++)
{
if (((CheckBox)gvemp.Rows[i].FindControl("cbAssign")).Checked)
{
tempempList.Add(((Label)gvemp.Rows[i].FindControl("lblempSeqNo")).Text);
}
}现在我有了List,Employee对象由以下属性组成: empID、empName、empAge、empSalary
现在,对于来自tempempList的每个empID,我需要填充列表
我不确定如何填充emp。
感谢您的帮助
发布于 2011-11-13 12:46:38
List<T>对象只是ArrayList的强类型版本(泛型)。ArrayList保留用于传统用途,在必要时应使用List<T>。
您可以像调用ArrayList.Add()方法一样调用List<T>.Add()方法。所以就像这样:
emps.Add(yourValue);
这应该就足够了。
https://stackoverflow.com/questions/8109522
复制相似问题