Today, it took me half a day to complete the add and delete functions for this stuff. I have been debugging for a long time because I didn't pay attention to the details!
The "add" button of a single machine dynamically creates a table to present the selected personnel data. The Code is as follows:
// Create the selected private void createselectnodeinfo () {If (Al. count> 0) {table TB = This. selectemployetable; htmlinputcheckbox cbox; dropdownlist DDL; For (INT I = 0; I <Al. count; I ++) {tablerow TR = new tablerow (); tablecell TC1 = new tablecell (); cbox = new htmlinputcheckbox (); cbox. id = ("cbox" + I ). tostring (); tc1.controls. add (cbox); tr. cells. add (TC1); tablecell TC2 = new tablecell (); tc2.text = al [I]. tostring (); tr. cells. add (TC2); tablecell TC3 = new tablecell (); DDL = new dropdownlist (); DDL. id = ("DDL" + I ). tostring (); DDL. datasource = bindddldata (); DDL. databind (); tc3.controls. add (DDL); tr. cells. add (TC3); TB. rows. add (TR); this. pnlselect. controls. add (TB );}}}
The single-host "delete" button will delete the corresponding row according to the selected check box. The algorithm here is a bit Rao. We know that when several check boxes are selected at the same time, each traversal is performed, the Rows marked by a check box will be deleted from top to bottom, so that the number of rows in the table will be reduced by one row, so we can declare a variable index to dynamically note the changes in the number of rows in the table, to delete multiple rows. The Code is as follows:
function DelRow() { var tb = document.getElementById("AddEmployee1_selectEmployeTable"); if (tb.hasChildNodes) { var rowCount = tb.childNodes[0].childNodes.length; var index = 0; for (var i = 0; i < rowCount; i++) { var child = tb.childNodes[0].childNodes[index]; index++; var mark = child.childNodes[0].childNodes[0].checked; if (mark) { child.parentNode.removeChild(child); index--; } } }}