ASP.NET dynamically generate input pages, as well as generate control, verification of input data, etc.
Sometimes, according to different data tables, to generate different input pages, the structure of these data tables is different, then the dynamic output control constitutes the input page, putting the structure of these tables in a special Type table, Such as the name, type, size, and English watch name, etc. First place a Table control on the page, place a DROPDOWNLIST control, and the DROPDOWNLIST binding database to generate the table name of the input page. Generating page code as follows: cnn.open (); int cellw; string type; string Sql = "select CHINANAME, HOW, TYPE from Type where OWNER = '" DropDownList1.SelectedValue "'"; OleDbDataAdapter myDa = new OleDbDataAdapter () Myda.selectcommand = new oledbcommand (SQL, CNN); DataSet myds = new dataset (); myda.fill (MyDS, "TYPE"); for (int i = 0; i Label mylab = new label (); mylab.id = "labe" i.tostring (); mylab.text = "" myds.tables [0] .rows [i] .ITEMARRY.GETVALUE (0) .tostring ( ) ":"; Mylab.enableviewstate = true; myLab.width = 100; Textbox mytxt = new textBox (); mytxt.id = "txt" i.Tostring (); mytxt.enableviewstate = true; type = myds.tables [0] .rows [i] .ITEMARRY.GETVALUE (2) .tostring (); Cellw = int.parse (myds.tables [0] .rows [i] .ITEMARRAY.GETVALUE (1) .tostring ()); if (cellw <= 50) {mytxt.height = 24; mytxt.width = 400; } IF (cellw> 50 && cellw <= 100) {mytxt.height = 50; mytxt.width = 400; mytxt.textMode = textBoxMode.Multiline;} if (cellw> 100 && cellw <= 200) {mytxt.height = 60; mytxt. Width = 400; myTxt.TextMode = TextBoxMode.MultiLine;} if (cellw> 200 && cellw <= 500) {myTxt.Height = 80; myTxt.Width = 400; myTxt.TextMode = TextBoxMode.MultiLine;} newcell1.Controls.Add ( NEWROW.CELLS.ADD (newcell1); newcell2.controls.add (mytxt); newrow.cells.add (newcell2); IF (type == "decimal") {regularexpressionValidator Rev = new regularExpressionValidator (); ref.id = "rev" i.toTString (); ref.ErrorMessage = "This Bank can only fill in the number, please enter!"; Rev.ControlTovAlidate = "txt" i.tostring () "" "" "" "" ""; ref.validationExpression = @ "/ d (/./ D )? $"; ref.width = 250; newcell3.controls.add (REV); NEWROW.CELLS.ADD (Newcell3); Table1.Rows.Add (newrow);} myds.clear (); cnn.close (); Save data input by generated page to the database: string strsql = "INSERT INTO" BM "("; try {for (int i = 0; i } CatCH { }