从视图状态到列表获取数据(视图状态具有表) [英] Get data from view state to list (viewstate have table)
本文介绍了从视图状态到列表获取数据(视图状态具有表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在一个像下面这样的列表中有一个数据,现在我想从已经包含表的viewstate中获取数据,我想要一列.我该怎么办?
Suppose I have a data in a list like below and now I want to get data from viewstate which already contain table in that I want one column. How can I do that?
public List<Employee> GetEmployeeList()
{
List<Employee> empList = new List<Employee>();
empList.Add(new Employee() { ID = 1, Email = "Mary@somemail.com"});
empList.Add(new Employee() { ID = 2, Email = "John@somemail.com"});
empList.Add(new Employee() { ID = 3, Email = "Amber@somemail.com"});
empList.Add(new Employee() { ID = 8, Email = "Jonay@somemail.com"});
empList.Add(new Employee() { ID = 9, Email = "Robert@somemail.com"});
empList.Add(new Employee() { ID = 10, Email = "Krishna@somemail.com" });
return empList;
}
推荐答案
如果我正确地回答了您的问题,则说明viewstate中有一个数据表,并且您想添加您上面显示的列表中的特定列.如果是这样,您可以:
1-从viewstate获取数据表.DataTable dataTable = ViewState["myDataTable"]
2-从GetEmployeeList(...)获取列表.List<Employee> listEmployee = GetEmployeeList();
3-遍历数据表的行并将值添加到列表变量.
If i''m getting your question right you have a datatable in the viewstate and you want to add all the values from rows of a particular column to the list you have shown above. if that is the case you can:
1- Get Datatable from viewstate.DataTable dataTable = ViewState["myDataTable"]
2- Get the list from GetEmployeeList(...).List<Employee> listEmployee = GetEmployeeList();
3- Iterate through rows of datatable and add values to your list variable.
for(rowIndex=0; rowIndex<datatable.rows.count;>{
string columnValue = dataTable.Rows[rowIndex]["email"];
Employee emp = new Employee(){ID=someID, Email=columnValue});
}
希望对您有所帮助.
谢谢,
Hemant
Hope it will help.
thanks,
Hemant
这篇关于从视图状态到列表获取数据(视图状态具有表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文