<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../Styles/basic.css" type="text/css">
<title>Table-3.aspx</title>
<script language="c#" runat="server">
void Button1_Click(Object sender,EventArgs e)
{
int numrows = int.FromString(DropDownList1.SelectedItem.Value);
int numcells = int.FromString(DropDownList2.SelectedItem.Value);
Tabel1.Style["Color"] = DropDownList3.SelectedItem.Value;
//Using Loop to Create Table
for(int j=0;j<numrows;j++)
{
TableRow r = new TableRow();
for(int i=0;i<numcells;i++)
{
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("Row:" + j.ToString()+", Cell:" + i.ToString()));
r.Cells.Add(c);
}
Tabel1.Rows.Add(r);
}
}
</script>
</head>
<body>
<form runat="server">
<asp:Table ID="Tabel1" BorderWidth="1px" GridLines="Both" Runat="server">
</asp:Table>
<p>
Table Line:
<asp:DropDownList id="DropDownList1" runat="server" class="selectstyle">
<asp:ListItem Value="1">One Row</asp:ListItem>
<asp:ListItem Value="2">Second Rows</asp:ListItem>
<asp:ListItem Value="3">Three Rows</asp:ListItem>
<asp:ListItem Value="4">Four Rows</asp:ListItem>
</asp:DropDownList>
Table Cell:
<asp:DropDownList id="DropDownList2" runat="server" class="selectstyle">
<asp:ListItem Value="1">One Cell</asp:ListItem>
<asp:ListItem Value="2">Second Cells</asp:ListItem>
<asp:ListItem Value="3">Three Cells</asp:ListItem>
<asp:ListItem Value="4">Four Cells</asp:ListItem>
</asp:DropDownList>
Tabel Color:
<asp:DropDownList id="DropDownList3" runat="server" class="selectstyle">
<asp:ListItem Value="red">Red Color</asp:ListItem>
<asp:ListItem Value="blue">Blue Color</asp:ListItem>
<asp:ListItem Value="green">Green Color</asp:ListItem>
<asp:ListItem Value="black">Black Color</asp:ListItem>
</asp:DropDownList>
<p>
<asp:Button
id="Button1"
Text="Create Tabel"
OnClick="Button1_Click"
class="SubmitStyleSmall"
Runat="server">
</asp:Button>
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../Styles/basic.css" type="text/css">
<title>Table-3.aspx</title>
<script language="c#" runat="server">
void Button1_Click(Object sender,EventArgs e)
{
int numrows = int.FromString(DropDownList1.SelectedItem.Value);
int numcells = int.FromString(DropDownList2.SelectedItem.Value);
Tabel1.Style["Color"] = DropDownList3.SelectedItem.Value;
//Using Loop to Create Table
for(int j=0;j<numrows;j++)
{
TableRow r = new TableRow();
for(int i=0;i<numcells;i++)
{
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("Row:" + j.ToString()+", Cell:" + i.ToString()));
r.Cells.Add(c);
}
Tabel1.Rows.Add(r);
}
}
</script>
</head>
<body>
<form runat="server">
<asp:Table ID="Tabel1" BorderWidth="1px" GridLines="Both" Runat="server">
</asp:Table>
<p>
Table Line:
<asp:DropDownList id="DropDownList1" runat="server" class="selectstyle">
<asp:ListItem Value="1">One Row</asp:ListItem>
<asp:ListItem Value="2">Second Rows</asp:ListItem>
<asp:ListItem Value="3">Three Rows</asp:ListItem>
<asp:ListItem Value="4">Four Rows</asp:ListItem>
</asp:DropDownList>
Table Cell:
<asp:DropDownList id="DropDownList2" runat="server" class="selectstyle">
<asp:ListItem Value="1">One Cell</asp:ListItem>
<asp:ListItem Value="2">Second Cells</asp:ListItem>
<asp:ListItem Value="3">Three Cells</asp:ListItem>
<asp:ListItem Value="4">Four Cells</asp:ListItem>
</asp:DropDownList>
Tabel Color:
<asp:DropDownList id="DropDownList3" runat="server" class="selectstyle">
<asp:ListItem Value="red">Red Color</asp:ListItem>
<asp:ListItem Value="blue">Blue Color</asp:ListItem>
<asp:ListItem Value="green">Green Color</asp:ListItem>
<asp:ListItem Value="black">Black Color</asp:ListItem>
</asp:DropDownList>
<p>
<asp:Button
id="Button1"
Text="Create Tabel"
OnClick="Button1_Click"
class="SubmitStyleSmall"
Runat="server">
</asp:Button>
</form>
</body>
</html>
解决方案 »
- 如何让repeater里的按钮执行 response.
- 实现新闻内容的上一篇下一篇的问题
- 自动创建时间的最便捷快速的方法
- 做了一个留言本,卡住了!!关于postback的问题
- 急!急!急!急!求各位大虾指点!
- 按首字母排序像58城市切换那样
- 关于新建项目的错误
- 新建asp.net应用程序出错,高手指点迷津。
- 大家好,问个简单问题:我在网上下载的ASP.NET源代码如何配置使用??
- 在DataList中的File Field控件,怎么找不到,谢谢!
- datagrid中限定某列的字符长度应该怎么做?把多于的改成...
- CS0234: 类型或命名空间名称“SQL”在类或命名空间“System.Data”中不存在(是否缺少程序集引用?)??
改为 var numrows= eval(DropDownList1.SelectedItem.Value)
这样程序就把numrows当成int类型了。
var numrows= eval(DropDownList1.SelectedItem.Value);
编译不过;
int numrows = int.Parse(DropDownList1.SelectedItem.Value);
ok了~~~