注册 登录
编程论坛 ASP.NET技术论坛

在开始写程序时遇到的问题

minnie5086 发布于 2007-10-20 10:25, 477 次点击

下面是我写的例题,因为是新手,所以问的问题有点差劲。asp.net,C#
1、红色加粗的代码是需要自己手写上去的吗?
2、这段代码里,蓝色部分原始值为false,可是在这段代码的功能中,必须改成true,才能实现。

请帮我解释一下好吗。

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="true" Inherits="WebApplication8.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="C#" runat="server">
void Page_Load(Object sender,EventArgs e)
{
int numrows = int.Parse(DropDown1.SelectedItem.Value);
int numcells = int.Parse(DropDown2.SelectedItem.Value);
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("行" + j.ToString() + "单元格" + i.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}

</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P><FONT face="宋体">动态生成表</FONT></P>
<P><FONT face="宋体">
<asp:Table id="Table1" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
CellPadding="5" CellSpacing="0" GridLines="Both"></asp:Table></FONT></P>
<P><FONT face="宋体">表行:
<asp:DropDownList id="DropDown1" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList>表单元格:
<asp:DropDownList id="DropDown2" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList></FONT></P>
<P>
<asp:Button id="Button1" runat="server" Text="生成表"></asp:Button></P>
</form>
</body>
</HTML>


[此贴子已经被作者于2007-10-20 10:35:06编辑过]

5 回复
#2
jxnuwy042007-10-20 18:27
AutoEventWireup:
指示控件的事件是否自动匹配 (Autowire)。如果启用事件自动匹配,则为 true;否则为 false。默认值为 true
#3
yunj11052007-10-22 08:56

红色代码在.cs里自己就有的

#4
师妃暄2007-10-22 08:59
你双击页面。就会自动生成红色的代码
#5
jxnuwy042007-10-22 13:51
void Page_Load(Object sender,EventArgs e)
{
int numrows = int.Parse(DropDown1.SelectedItem.Value);
int numcells = int.Parse(DropDown2.SelectedItem.Value);
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("行" + j.ToString() + "单元格" + i.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
这些代码应该写在cs文件中吧。
#6
beblue2007-10-23 10:31
Page_Load 函数表示网页第一次被打开就会自动执行的函数
1