c# - Not able to store information while postback after creating dynamic dropdown in ASP.NET -
here code
after button 2 click event creating dropdown in table rows when try save button 1 click event disappear. have not find solution regarding this. have used find control view state etc it's not helping.
i want store selected values of dropdown after button_1 click event starts.
public partial class studentclasssectionmapping : system.web.ui.page { protected void page_load(object sender, eventargs e) { if(!ispostback) { classcode.enabled = false; } } protected void button2_click(object sender, eventargs e) { updatemodalshowflag.value = "true"; check.value = "true"; createtablerows(); } private void createtablerows() { long h = long.parse(linkbuttonidcarrier.value); list<studentsclasssectionmapping.studentsclasssectionmappingform> allstudentsinclass = studentsclasssectionmapping.getstudentsinclass(h); classmaster.classmasterform classcode = schoolclasses.getinfo(h); classcode.text = classcode.ccode; list<studentsclasssectionmapping.studentsclasssectionmappingform> allsectionsinclass = studentsclasssectionmapping.getsectionsinclass(h); foreach (studentsclasssectionmapping.studentsclasssectionmappingform studentlist in allstudentsinclass) { tablerow row = new tablerow(); tablecell cell1 = new tablecell(); tablecell cell2 = new tablecell(); tablecell cell3 = new tablecell(); dropdownlist t = new dropdownlist(); t.items.add("no section"); foreach (studentsclasssectionmapping.studentsclasssectionmappingform sectionlist in allsectionsinclass) { t.items.add(sectionlist.sssection); t.items[t.items.count - 1].value = sectionlist.sssectionid.tostring(); } t.attributes.add("class", "form-control"); t.id = studentlist.ssstudentid.tostring(); cell1.text = studentlist.ssname; cell2.text = studentlist.ssregistrationnumber; cell3.controls.add(t); row.cells.add(cell1); row.cells.add(cell2); row.cells.add(cell3); table1.rows.add(row); } } protected void button1_click(object sender, eventargs e) { createtablerows(); long h = long.parse(linkbuttonidcarrier.value); list<studentsclasssectionmapping.studentsclasssectionmappingform> allstudentsinclass = studentsclasssectionmapping.getstudentsinclass(h); foreach (studentsclasssectionmapping.studentsclasssectionmappingform studentlist in allstudentsinclass) { dropdownlist d = table1.findcontrol(studentlist.ssstudentid.tostring()) dropdownlist; if (d != null) { if (d.selectedindex != 0) { studentsclasssectionmapping.studentsclasssectionmappingform studentsectionmapping = new studentsclasssectionmapping.studentsclasssectionmappingform(); studentsectionmapping.ssclassid = h; studentsectionmapping.ssstudentid = studentlist.ssstudentid; studentsectionmapping.ssstudentid = long.parse(d.selecteditem.value); studentsclasssectionmapping.addsectionstudentmapping(studentsectionmapping); } else { studentsclasssectionmapping.studentsclasssectionmappingform studentsectionmapping = new studentsclasssectionmapping.studentsclasssectionmappingform(); studentsectionmapping.ssclassid = h; studentsectionmapping.ssstudentid = 0; studentsectionmapping.ssstudentid = 0; studentsclasssectionmapping.addsectionstudentmapping(studentsectionmapping); } } } }
it vanished/disappear because added dynamically on page. if want or want reserver control dynamically created need recreate again , need add dynamically.
here example of how can : how create controls dynamically in asp.net , retrieve values it
Comments
Post a Comment