c# - Handling similar checkbox values in .NET Web App -


list<char> errorlist = new list<char>();         if (meetingerrorcheckbox.checked)             errorlist.add('m');         if (scheduledmachinedowntimecheckbox.checked)             errorlist.add('s');         if (toolingcheckbox.checked)             errorlist.add('t');         if (processissuecheckbox.checked)             errorlist.add('p');         if (operatormaintenancecheckbox.checked)             errorlist.add('o');         if (vactioncheckbox.checked)             errorlist.add('v');         if (cellleadcheckbox.checked)             errorlist.add('c');         if (waittoolscheckbox.checked)             errorlist.add('w');         if (unscheduledmaintenancecheckbox.checked)             errorlist.add('u');         if (waitmaterialcheckbox.checked)             errorlist.add('a');         if (waitinspectioncheckbox.checked)             errorlist.add('i');         if(alternatedepartmentcheckbox.checked)             errorlist.add('d');         if (trainingcheckbox.checked)             errorlist.add('b'); 

is there way make this.. cleaner? thought using interface or something, seems there isn't easier way .net web forms , asp:checkbox.

basically i'm using list fill intermediate table between 2 tables in database , i'm wondering of there's better way, since still need check on box checked regardless if can iterate through boxes.

the way simplify rename checkboxes error0, error1, error2, etc... , iterate though them doing this:

list<char> errorlist = new list<char>(); int totalerrors = 13; //change accordingly char[] errorid = new char['m', 's', 't', 'p', 'o', 'v', 'c', 'w', 'u', 'a', 'i', 'd', 'b']; for(int = 0; < totalerrors; i++) {     string controlid = "error" + i.tostring();     control errorbutton = findcontrol(controlid);     if(errorbutton.checked)          errorlist.add(char[i]); } 

if use remember make id of checkbox correspond element in char[]. example, element 0 in char array used m, means checkbox want have give error m, name error0. code allow add error list without having huge list of if statements. , of course make sure update total error variable accordingly.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -