Html dynamic tables and dynamic tables
1 <table id = "opttb"> 2 <asp: Repeater ID = "tempOptions" runat = "server"> 3 <ItemTemplate> 4 <tr ondblclick = "tt (this) "> 5 <td> <% # Eval (" XH ") %> </td> 6 <td> <% # Eval (" XXBH ") %> </td> 7 <td> <% # Eval ("XXMC") %> </td> 8 <td> <% # Eval ("ISOK ") %> </td> 9 </tr> 10 </ItemTemplate> 11 </asp: Repeater> 12 </table>View Code
Html dynamic table background
1 protected void DelOption_Click (object sender, EventArgs e) 2 {3 var templist = new List <tableModel> (); 4 var DelNO = this. delNO. value; 5 if (Session ["tempdate"]! = Null) 6 {7 var tempdata1 = Session ["tempdate"] as List <tableModel>; 8 9 for (int I = 0; I <tempdata1.Count; I ++) 10 {11 templist. add (tempdata1 [I]); 12} 13} 14 templist. removeAt (Convert. toInt16 (DelNO. substring (0, 1); 15 16 list. clear (); 17 18 for (int k = 0; k <templist. count; k ++) 19 {20 tableModel tm = new tableModel (); 21 tm. XH = k. toString (); 22 tm. XXBH = NumtoChar (k. toString (); 23 tm. XXMC = tem Plist [k]. XXMC; 24 tm. ISOK = templist [k]. ISOK; 25 tm. remark = templist [k]. remark; 26 list. add (tm); 27} 28 29 this. tempOptions. dataSource = ToDataTable (list); 30 tempOptions. dataBind (); 31 templist. clear (); 32 list. clear (); 33 34} 35 36 37 38 protected void addOption_Click (object sender, EventArgs e) 39 {40 if (Session ["tempdate"]! = Null) 41 {42 var tempdata1 = Session ["tempdate"] as List <tableModel>; 43 for (int I = 0; I <tempdata1.Count; I ++) 44 {45 list. add (tempdata1 [I]); 46} 47} 48 tableModel tm = new tableModel (); 49 tm. XH = (list. count ). toString (); 50 tm. XXBH = NumtoChar (tm. XH); 51 tm. XXMC = this. questions. text; 52 tm. ISOK = this. ISOK1.Checked = true? "No": "Yes"; 53 tm. remark = this. remark. text; 54 var tt = ISOK2.Checked; 55 list. add (tm); 56 this. tempOptions. dataSource = ToDataTable (list); 57 tempOptions. dataBind (); 58 Session ["tempdate"] = list; 59 list. clear (); 60} 61 62 63 64 65 public static DataTable ToDataTable (IList list) 66 {67 DataTable result = new DataTable (); 68 if (list. count> 0) 69 {70 PropertyInfo [] propertys = list [0]. getType (). getProperties (); 71 foreach (PropertyInfo pi in propertys) 72 {73 result. columns. add (pi. name, pi. propertyType); 74} 75 76 for (int I = 0; I <list. count; I ++) 77 {78 ArrayList tempList = new ArrayList (); 79 foreach (PropertyInfo pi in propertys) 80 {81 object obj = pi. getValue (list [I], null); 82 tempList. add (obj); 83} 84 object [] array = tempList. toArray (); 85 result. loadDataRow (array, true); 86} 87} 88 return result; 89}View Code