动态创建TABLE的行与列
发表于:2007-06-30来源:作者:点击数:
标签:
%@ 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.AddMi
<%@ 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://www.ltesting.net