动态创建TABLE的行和列

2008/10/4 16:54:54 来源:互联网 【 】 浏览:4774次

动态创建TABLE的行和列


<%@ 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>

  • 上一篇文章:网友原创:从N层到.NET详细剖析原理
  • 下一篇文章:ASP控制Iframe高度自适应
    当前地址:https://dns2003.com:443/help/hlp_dtl.asp?nid=10000301
    更多帮助登录: http://www.dns2003.com/help
    业务请咨询E网时代客服部