码迷,mamicode.com
首页 > Web开发 > 详细

html动态表格

时间:2015-03-16 06:14:32      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 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

 

html动态表格

标签:

原文地址:http://www.cnblogs.com/yuanjiehot/p/4340923.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!