zoukankan      html  css  js  c++  java
  • 原创 html动态表格

     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
  • 相关阅读:
    js正则表达式
    js遍历对象属性
    C# 带Cookies发送请求
    C# Cookies设置和读取
    C# ref 和 out 的使用
    jq 禁用复选框 和输入框
    C++学习之嵌套类和局部类
    C++学习之this指针
    C++学习之运算符重载的总结
    Labview中引用,属性节点,局部变量之间的区别
  • 原文地址:https://www.cnblogs.com/yuanjiehot/p/4340923.html
Copyright © 2011-2022 走看看