c# - Combining generic lists -
right i'm combining 3 lists union. want populate gridview values, problem here in list want separate values. example:
- listitem [0] "firstname + " " + lastname"
- listitem 1 employeeid
- listitem [2] "second emp firstname + " " + second emp lastname"
- listitem [3] second emp employeeid
i want show on gridview. code @ moment:
list<string> ulist = _searchemplist.union(_searchtechskilllist).union(_searchassignlist).tolist(); string s = string.empty; (int = 0; < ulist.count; i++) { s += ulist[i] + ","; } string[] split = s.split(','); datarow dr = _dt.newrow(); dr["name"] = split[0]; //firstname + +lastname dr["employeeid"] = split[1]; //employeeid _dt.rows.add(dr); session["datatablesearch"] = _dt; gridviewsearchresults.datasource = _dt; gridviewsearchresults.databind();
i don't understand why you're going trouble. following want. whether it's want different question.
list<string> ulist = _searchemplist.union(_searchtechskilllist).union(_searchassignlist).tolist(); int = 0; while (i < ulist.count-1) { datarow dr = _dt.newrow(); dr["name"] = ulist[i]; //firstname + +lastname dr["employeeid"] = ulist[i+1]; //employeeid _dt.rows.add(dr); ++i; }
that duplicates logic in original code, loop asked for. whether it's going give results think should open question. union
combines 2 lists , creates new list distinct values. if there duplicate values in 2 lists, they'll show once in result.
also, union
makes no guarantee order of items in final list.
Comments
Post a Comment