Table ,这个有点HTML基础的人都知道了,是表格的意思啦,也是布局的一个重要方法,如果是用DW的话,你就会知道他有多重要了!
而VS推出的Table服务器控件最大的特色当推他可以动态是控制表格的行列数,下面还是做个演示:
演示一: 动态添加表格行和列,在特定的格里写特定的字,并在当前单元格里面把坐标写出来
效果如下
洪川洪川洪川洪川洪川2,12,22,32,42,53,13,23,33,43,5


代码没有分离,全部在这里!


<%

@ Page Language="C#" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script runat="server">



protected void Page_Load(object sender, EventArgs e)


{

}


protected void Button1_Click(object sender, EventArgs e)


{

int rn = int.Parse(rows.SelectedValue);//得到需要增加的行数

int cn = int.Parse(cell.SelectedValue);//得到需要增加的列数


for (int i = 1; i <= rn; i++)//


{//进入外部循环,也就是循环增加表行

TableRow tr = new TableRow();//申明一个表格行

for (int j = 1; j <= cn; j++)


{//进入内部循环,以增加表格列

TableCell tc = new TableCell();//申明一个表格列

if (i == 1)


{//如果是第一行,就增加下面的字

tc.Controls.Add(new LiteralControl("洪川"));

}

else


{//否则

tc.Controls.Add(new LiteralControl(i.ToString() + "," + j.ToString()));//在表格里增加当前是行,列坐标

}

tr.Cells.Add(tc);//把列增加到行里面去

}

Table1.Rows.Add(tr);//把行增加到表里去

}

}

</script>


<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>无标题页</title>

</head>

<body>

<form id="form1" runat="server">

<div>

Table ,这个有点HTML基础的人都知道了,是表格的意思啦,也是布局的一个重要方法,如果是用DW的话,你就会知道他有多重要了!<br />

而VS推出的Table服务器控件最大的特色当推他可以动态是控制表格的行列数,下面还是做个演示:<br />

<br />

<strong>

演示一: 动态添加表格行和列,在特定的格里写特定的字,并在当前单元格里面把坐标写出来</strong><br />

<asp:Table ID="Table1" runat="server" BorderColor="Black" BorderStyle="Dashed" BorderWidth="1px" GridLines="Both">

</asp:Table>

<asp:DropDownList ID="rows" runat="server">

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

<asp:ListItem>4</asp:ListItem>

</asp:DropDownList>

<asp:DropDownList ID="cell" runat="server">

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

<asp:ListItem>4</asp:ListItem>

<asp:ListItem>5</asp:ListItem>

</asp:DropDownList>

<asp:Button ID="Button1" runat="server" Text="给我建个表格来" OnClick="Button1_Click" /><br />

<br />

</div>

</form>

</body>

</html>