我在aspx文件上中写了一个page_load()函数,如何让page_load中的代码执行,谢谢,新手,请帮忙
gsoft 2006-10-08 03:52:54 <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<%@ Import Namespace="System.Globalization"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="C#" runat="server">
public SqlDataReader myReader;
public String myhtml;
protected void Page_Load(Object Src, EventArgs E ) {
SqlConnection mySQLConnection = new SqlConnection("server=localhost;uid=sa;pwd=newmanager;database=northwind");
SqlCommand mySQLCommand = new SqlCommand("select * from customers", mySQLConnection);
try
{
mySQLConnection.Open();
myReader = mySQLCommand.ExecuteReader();
myhtml="<Table>";
myhtml+="<TR>";
myhtml+="<TD><B>Customer ID</B></TD>";
myhtml+="<TD><B>Company Name</B></TD>";
myhtml+="</TR>";
while (myReader.Read())
{
myhtml+="<TR>";
myhtml+="<TD>" + myReader["CustomerID"].ToString() + "</TD>";
myhtml+="<TD>" + myReader["Companyname"].ToString() + "</TD>";
myhtml+="</TR>";
}
myhtml+="</Table>";
}
catch(Exception ee)
{
myhtml=ee.ToString();
}
finally
{
Response.Write(myhtml);
}
}
</script>
</HEAD>
<body BGCOLOR="#0099ff">
<form>
</form>
</body>
</HTML>
上面代码运行后什么也不显示,我想应该是page_load()事件没有响应,不知道应该如何调用这个事件,让page_load中的代码执行,谢谢,新手,请帮忙