原创 html动态表格

2018-06-17 21:17:20来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

 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

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:C#中方法Show.和ShowDialog的使用区别

下一篇:.net memcache