·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 原创html动态表格

原创html动态表格

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23
 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动态表格后台

 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 = templist[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 ? "否" : "是";
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