动态创建TABLE的行与列

类别:Asp 点击:0 评论:0 推荐:

<%@ Page Language="C#"%>
<script runat="Server">

void btn_click(object sender, EventArgs e)
{
 ArrayList x = new ArrayList();
 if (ViewState["myList"] != null)
 {
  x = (ArrayList)ViewState["myList"];
 }
 x.Add(DateTime.Now.ToString() + "," + DateTime.Now.AddMinutes(1).ToString());
 ViewState["myList"] = x;
 for(int i=0;i<x.Count;i++)
 {
     TableRow tr = new TableRow();
     TableCell tc1 = new TableCell();
     TableCell tc2 = new TableCell();
     string[] str = x[i].ToString().Split(',');
     tc1.Text = str[0];
     tc2.Text = str[1];
     tr.Cells.Add(tc1);
     tr.Cells.Add(tc2);
     tbl.Rows.Add(tr);
    }
}
</script>
<html>
<body>
<form runat="Server">
<asp:Table id=tbl runat=server border=1 EnableViewState="false">
 <asp:TableRow>
  <asp:TableCell>列1</asp:TableCell>
  <asp:TableCell>列2</asp:TableCell>
 </asp:TableRow>
</asp:Table>
<asp:button id="btn" runat="Server" text="btn" onclick="btn_click"/>
</form>
</body>
</html>

本文地址:http://com.8s8s.com/it/it8117.htm