Arvind Chourasiya

Arvind Chourasiya

  • NA
  • 933
  • 134.3k

bind nodes and leafnodes dynamically in Exapandable listview

Oct 7 2016 3:18 AM
Hii C#Guys,
 
i need to bind menus and submenus dynamically in Expandable listview, im getting data from API's in this format
 
  1. [  
  2.   {  
  3.     "applicationid": 24347,  
  4.     "applicationname""Timetable Staff",  
  5.     "ParentApplicationId": 24444,  
  6.     "pagelink""~/Web/Reports/TimeTableStaff.aspx",  
  7.     "PageName""Reports/TimeTableStaff",  
  8.     "sortorder"null,  
  9.     "IconCD"null  
  10.   },  
  11.   {  
  12.     "applicationid": 24875,  
  13.     "applicationname""Question Bank-Scholastic",  
  14.     "ParentApplicationId": 24438,  
  15.     "pagelink""~/Web/QuestionBank/SearchQuestions.aspx",  
  16.     "PageName""QuestionBank/Search",  
  17.     "sortorder"null,  
  18.     "IconCD"null  
  19.   },  
  20.   {  
  21.     "applicationid": 24879,  
  22.     "applicationname""Tests-Scholastic",  
  23.     "ParentApplicationId": 24438,  
  24.     "pagelink""~/Web/QuestionBank/QuestionPaperSearch.aspx",  
  25.     "PageName""TestsScholastic/Search",  
  26.     "sortorder"null,  
  27.     "IconCD"null  
  28.   },  
  29.   {  
  30.     "applicationid": 34113,  
  31.     "applicationname""Staff Leave Management",  
  32.     "ParentApplicationId": 24439,  
  33.     "pagelink""~/Web/LeaveManagement/LeaveManagementStaffList.aspx",  
  34.     "PageName""LeaveManagementStaff/List",  
  35.     "sortorder"null,  
  36.     "IconCD"null  
  37.   },  
  38.   {  
  39.     "applicationid": 24276,  
  40.     "applicationname""Subjects",  
  41.     "ParentApplicationId": 24438,  
  42.     "pagelink""~/Web/Course/CourseSearch.aspx",  
  43.     "PageName""Course/Search",  
  44.     "sortorder": 1,  
  45.     "IconCD"null  
  46.   },}  
 like that i'm getting 100's of records, if any record have parentid null means that record parent only, and parent record applicationid is same as parentid in other record means that record is child(parent child relationship based on applicationid and parentid here)
 
im using foreach loop to add all prent in one list
 
  1. var response = SisApi.Get("Auth/getmenu"out issucsesParam, UserId);  
  2.            Person pobj = new Person();  
  3.            var person = new Person { applicationname = "", ParentApplicationId = "", applicationid = "" };  
  4.            var menu2 = JsonConvert.DeserializeObject<List<Person>>(response);  
  5.   
  6.   
  7.            foreach (var n in menu2)  
  8.            {  
  9.                if (n.ParentApplicationId == null)  
  10.                {  
  11.                     
  12.                    ParentnodeNames.Add(n.applicationname);  
  13.                }  
  14.            }  
  
if parentnodes list have 20 records say Admin, Management, Library i'm statically creating that many List<String> like ListAdmin, ListManagement to add relevent child records
below
  1. foreach (var r in menu2)  
  2.             {  
  3.                 if (r.ParentApplicationId == "24439" || r.applicationname == "Admin")  
  4.                 {  
  5.                     AdminList.Add(r.applicationname);  
  6.   
  7.                 }  
  8.                 if (r.ParentApplicationId == "24443" || r.applicationname == "Management")  
  9.                 {  
  10.                     ManagementList.Add(r.applicationname);  
  11.                 }  
  12.   
  13.                 if (r.ParentApplicationId == "24438" || r.applicationname == "Academics")  
  14.                 {  
  15.                     AcademicsList.Add(r.applicationname);  
  16.                 }  
  17. }  
 finally im adding all list in Dicationary
 
  1. Dictionary<string, List<string>> childdata=new Dictionary<string,List<string>>();  
  2.   
  3. entnodeNames.Contains("Admin"))  
  4.         childdata.Add(ParentnodeNames[0], AdminList);  
  5.   
  6.     if (ParentnodeNames.Contains("Management"))  
  7.         childdata.Add(ParentnodeNames[1], ManagementList);  
  8.     if (ParentnodeNames.Contains("Academics"))  
  9.         childdata.Add(ParentnodeNames[2], AcademicsList);  
and setting to listview. 
 
here this my logic working fine for the same data if someone add more record in database my logic will fail i need to again modify my code and creating lists, please can anyone tell me the to add these menus dynamically
for reference purpose please see this demo
 
http://www.appliedcodelog.com/2016/06/expandablelistview-in-xamarin-android.html 
 
thanks :)