model view controller - Convert an object into list or array MVC -
i have mvc grid control passing collection controller object. object arraylist of rows grid , each row list represents instance of class called lineitem part of parent record class.
i trying load object class looping through object array, create instance of lineitem class, , add parent record class parent.additem(lineitem). had created follows
var items = requestdata.extrarequestdata["items"];
however determined, arraylist changed to
list<string> mylist; arraylist items = (arraylist)requestdata.extrarequestdata["items"]; mylist = items.cast<string>().tolist();
i trying convert arraylist list can loop through , load class.
model.parent parent = new model.parent(); model.lineitem lineitem = new model.lineitem(); (int = 0; < mylist.length; i++){ lineitem.a = item.a, lineitem.b = item.b parent.additem(lineitem) }
i getting following error on line set mylist = items:
{"unable cast object of type 'system.collections.hashtable' type 'system.string'."}
what missing convert can load class?
since each item in arraylist hashtable, ended looping through follows: parentclass reconhdr = new parentclass();
foreach (system.collections.hashtable o in items) { //lineitem.lineseq = convert.toint32(item.value); arraylist list = new arraylist(o.values); childclass lineitem = new childclass(); lineitem.stmntdocnum = list[0].tostring(); lineitem.prtlamt = convert.todouble(list[1]); lineitem.glacctcode = list[2].tostring(); lineitem.lineseq = convert.toint32(list[3]); lineitem.clinicid = convert.toint32(list[4]); lineitem.prtltrandate = convert.todatetime(list[5]); lineitem.stmnttrandate = convert.todatetime(list[6]); lineitem.prtlfinrptdate = convert.todatetime(list[7]); lineitem.stmntenddate = convert.todatetime(list[8]); lineitem.stmntamt = convert.todouble(list[9]); lineitem.prtldocnum = list[10].tostring(); lineitem.prtluniqueid = list[11].tostring(); reconhdr.additem(lineitem); }
Comments
Post a Comment