笨笨姐,如果你看到这个例子,告诉我中间那个private void BindNewsKindData()函数怎么写到类里面好吗?谢谢.
你是想把BindNewsKindData()写到NewsKinds.cs文件里?
欢迎光临我的博客: http://smallfools.blog./default.html
我将三个文件的内容简化出来给你看看,我这样引用就是不行,该怎么做?刚从ASP转到ASP.NET,搞得有点晕。
//index.aspx
<%@ Page Language="C#" autoeventwireup="false" codefile="index.aspx.cs" Inherits="_index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<form runat="server">
<asp:TextBox id="txt_str" runat="server" Text="test"></asp:TextBox>
</form>
</body>
</html>
//index.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TEST;
public partial class _index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
myClass myCls=new myClass();
txt_str.Text=myCls.startTime;
}
}
//testcls.cs
namespace TEST {
using System;
using System.Configuration;
using System.Xml;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Collections;
/// <summary>
/// Summary description for myClass.
/// </summary>
public class myClass{
public string startTime;
public myClass() {
startTime = DateTime.Now.ToString();
}
}
}
我改用Visual Web Developer 2005 Express Edition环境了,新建一个ASP.NET WEB Site,自动生成了Default.aspx和Default.aspx.cs文件,但是访问defualt.aspx网页时,居然也出错。我快对学习ASP.NET失去兴趣了。
//default.aspx
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text></asp:TextBox>
</div>
</form>
</body>
</html>
//default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("test");
}
}
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type '_Default'.
Source Error:
Line 1: <%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="_Default" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Source File: E:\aspnet\default.aspx Line: 1
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032