本人在知识不足的情况下实验第一个c# web项目,有问题如下:
default.aspx
页面没有任何内容
default.aspx.cs
我在 cs 文件中加一句:
using namespace connclass; 编译出错
应输入标识符;“namespace”是关键字 D:\日常办公文档\Win2003_MyDoc\Visual Studio 2008\WebSites\WebSite1\Default.aspx.cs
下面是我加的代码
public partial class _Default : System.Web.UI.Page
{
public string connstr;
protected void Page_Load(object sender, EventArgs e)
{
conndata conobj=new conndata; //这是自定义类
connstr=conobj.connectdatastr(0);//参数代表连接什么库文件
}
public void makemenu()
{
OleDbConnection olconn = new OleDbConnection(connstr); //我想写一个生成菜单的方法
olconn.Open(); //这里打开连接菜单表的连接.
但是我 如何把菜单放在我想放菜单的地方.
//在 asp 文件中,我只需要 <#include file=**.asp> 或者 调用一下函数.
//到了 .net 下. 因为代码与页分离,我如何想通过调用函数让菜单生成在我想要的地方呢
}
}
下面是自定义类 conndata.cs
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace connclass
{
public class connectdata
{
public string connectdatastr(int itype)
{
string cstr="";
switch(itype)
{
case 0: cstr = String.Format("Provider={0};Data Source=appdata/{1} ", ConfigurationSettings.AppSettings["Provider"], System.Web.HttpContext.Current.Server.MapPath("" + ConfigurationSettings.AppSettings["DataSource"])); break;
case 1: cstr = String.Format("{0}", ConfigurationSettings.AppSettings["SQLProvider1"]); break;
Default: cstr = "";
}
return cstr;
}
}
}
web.config
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Machin