我改了这个“.net摸到一点门槛”菜单,谁帮我再看看,出错的不是一般的信息:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1513: 应输入 }源错误: 行 203: }
行 204:
行 205: private void __Render__control1(System.Web.UI.HtmlTextWriter __output, System.Web.UI.Control parameterContainer) {
行 206:
行 207: #line 2 "F:\ASP_NET\enet_news\two_liandong\test.aspx"
源文件: c:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\44c64153\e1177d5b\6czicktj.0.cs 行: 205 下面是全部代码
<%@ Page language="c#" %>
<%
private System.Data.OleDb.OleDbConnection conn;
private DataTable get_dt(string sql)
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("data.mdb");
// OLEDBConnection cnn = new OLEDBConnection(cnnString);
// OLEDBDataAdapter cmd1 = new OLEDBDataAdapter("select * from class_1",cnn);
this.conn = new OleDbConnection(connstr);
this.conn.Open();
OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn);
OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand); DataSet myDataset = new DataSet();
try
{
myData.Fill(myDataset);
}
catch(Exception ex)
{
throw ex;
} this.conn.Close();
return myDataset.Tables[0];
}private void Page_Load(object sender, System.EventArgs e)
{
string sortid = this.Request.QueryString["sortid"];
if(sortid + "a" != "a")
{
this.down2_bind(sortid);
} if(!this.IsPostBack)
{
this.down1_bind();
}
}/// <summary>
/// 返回第2个下拉框需要的值给xmlhttp
/// </summary>
/// <param name="brc_id"></param>
private void down2_bind(string brc_id)
{
string mystr = "";
string sql = "select sortid,typename,typeid from class_2 where sortid = '" + sortid + "'";
DataTable mytab = this.get_dt(sql); if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
this.Response.Write(mystr);
this.Response.End();
}/// <summary>
/// 绑定第一个下拉框
/// </summary>
private void down1_bind()
{
string sql = "select sortid,sort from class_1";
DataTable mytab = this.get_dt(sql);
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "sortid";
this.DropDownList1.DataTextField = "sort";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>二级联动示例</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<SCRIPT LANGUAGE="JavaScript">
<!--
//以XML求取数据
function XmlPost(obj)
{
var svalue = obj.value;
var webFileUrl = "?sortid=" + svalue;
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
document.all("DropDownList2").length=0;
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
//alert(ary1[0].toString());
document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
alert(result);
}
}
//-->
</SCRIPT>
</form></body>
</html>
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1513: 应输入 }源错误: 行 203: }
行 204:
行 205: private void __Render__control1(System.Web.UI.HtmlTextWriter __output, System.Web.UI.Control parameterContainer) {
行 206:
行 207: #line 2 "F:\ASP_NET\enet_news\two_liandong\test.aspx"
源文件: c:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\44c64153\e1177d5b\6czicktj.0.cs 行: 205 下面是全部代码
<%@ Page language="c#" %>
<%
private System.Data.OleDb.OleDbConnection conn;
private DataTable get_dt(string sql)
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("data.mdb");
// OLEDBConnection cnn = new OLEDBConnection(cnnString);
// OLEDBDataAdapter cmd1 = new OLEDBDataAdapter("select * from class_1",cnn);
this.conn = new OleDbConnection(connstr);
this.conn.Open();
OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn);
OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand); DataSet myDataset = new DataSet();
try
{
myData.Fill(myDataset);
}
catch(Exception ex)
{
throw ex;
} this.conn.Close();
return myDataset.Tables[0];
}private void Page_Load(object sender, System.EventArgs e)
{
string sortid = this.Request.QueryString["sortid"];
if(sortid + "a" != "a")
{
this.down2_bind(sortid);
} if(!this.IsPostBack)
{
this.down1_bind();
}
}/// <summary>
/// 返回第2个下拉框需要的值给xmlhttp
/// </summary>
/// <param name="brc_id"></param>
private void down2_bind(string brc_id)
{
string mystr = "";
string sql = "select sortid,typename,typeid from class_2 where sortid = '" + sortid + "'";
DataTable mytab = this.get_dt(sql); if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
this.Response.Write(mystr);
this.Response.End();
}/// <summary>
/// 绑定第一个下拉框
/// </summary>
private void down1_bind()
{
string sql = "select sortid,sort from class_1";
DataTable mytab = this.get_dt(sql);
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "sortid";
this.DropDownList1.DataTextField = "sort";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>二级联动示例</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<SCRIPT LANGUAGE="JavaScript">
<!--
//以XML求取数据
function XmlPost(obj)
{
var svalue = obj.value;
var webFileUrl = "?sortid=" + svalue;
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
document.all("DropDownList2").length=0;
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
//alert(ary1[0].toString());
document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
alert(result);
}
}
//-->
</SCRIPT>
</form></body>
</html>
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1513: 应输入 }源错误: 行 6: System.Data;
行 7: System.Data.OleDb;
行 8: using System.Web.UI.WebControls;
行 9: /// <summary>
行 10: /// NestedRepeater 的摘要说明。
源文件: F:\ASP_NET\enet_news\class_1_2\list_class.aspx 行: 8
但我现在又做了,代码分离,,在VS中已经编译通过,,但是调试时DropDownList1;DropDownList2都得不到数据,,是不是我那又错了啊,谢谢,帮我看一下-------------WebForm1.aspx-----------<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<HTML>
<HEAD>
<title>二级联动示例</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<SCRIPT LANGUAGE="JavaScript">
<!--
//以XML求取数据
function XmlPost(obj)
{
var svalue = obj.value;
var webFileUrl = "?sortid=" + svalue;
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
document.all("DropDownList2").length=0;
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
//alert(ary1[0].toString());
document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
alert(result);
}
}
//-->
</SCRIPT>
</form>
</body>
</HTML>
-------------WebForm1.aspx.cs-----------
using System;
using System.Data;
using System.Data.OleDb;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
private System.Data.OleDb.OleDbConnection conn;
private DataTable get_dt(string sql)
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("data1.mdb");
this.conn = new OleDbConnection(connstr);
this.conn.Open();
OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn);
OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand); DataSet myDataset = new DataSet();
try
{
myData.Fill(myDataset);
}
catch(Exception ex)
{
throw ex;
} this.conn.Close();
return myDataset.Tables[0];
}private void Page_Load(object sender, System.EventArgs e)
{
string sortid = this.Request.QueryString["sortid"];
if(sortid + "a" != "a")
{
this.down2_bind(sortid);
} if(!this.IsPostBack)
{
this.down1_bind();
this.down2_2_bind();
}
}/// <summary>
/// 返回第2个下拉框需要的值给xmlhttp
/// </summary>
private void down2_bind(string sortid)
/// <param name="brc_id"></param>
{
string mystr = "";
//string sortid=DropDownList1.SelectedItem.Text ;
string sql = "select sortid,typename,typeid from class_2 where sortid = " + sortid ;
DataTable mytab = this.get_dt(sql); if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
this.Response.Write(mystr);
this.Response.End();
}/// <summary>
/// 绑定第一个下拉框
/// </summary>
private void down1_bind()
{
string sql = "select sortid,sort from class_1 ";
DataTable mytab = this.get_dt(sql);
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "sortid";
this.DropDownList1.DataTextField = "sort";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
} private void InitializeComponent()
{ }
private void down2_2_bind()
{
string sql = "select sortid,typename,typeid from class_2 where sortid =1" ;
DataTable mytab = this.get_dt(sql);
this.DropDownList2.DataSource = mytab;
this.DropDownList2.DataValueField = "typeid";
this.DropDownList2.DataTextField = "typename";
this.DropDownList2.DataBind();
//this.DropDownList2.Attributes.Add("onchange","XmlPost(this);");
}
}
}
-----------
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;如果去掉上面的,把WebForm1.aspx.cs源码直接放在WebForm1.aspx就能够执行的如果在 WebForm1.aspx 放了
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;就提示DropDownList1,2已经被定义我都快弄了大半天了,那位高手,帮帮忙啊,我急撒了..
打击真是大啊,我刚学代码分离,,路子都对了,就是不执行
:(
楼上的老大!!!我是没辙了,我整整弄了一天了啊。。
我现在把整个项目打成一个包,,
http://www.enet2004.com/WebApplication1.rar 你有空把我看看吧。。------------
再说,你经常发这个程序给初学者。。那程序零散的,需要拼装
现在是整个一个项目。改好了,可以以后传到空间上。。让别人下载吧,也少走好多弯路
-----------我在这个程序也修正了,你的程序,,在首页加载时,,第二个菜单没数据的小bug
谢谢了
================================================================
email:[email protected]
================================================================
我重新做了一个,明天就会放在我的blob里面(完整的项目文件),
地址:
http://www.cnblogs.com/hchxxzx
或
http://blog.csdn.net/hchxxzx/这里先贴出二级联动的代码(另外顺便做了一个三级联动)以下为页面代码down1.aspx
-------------------
<%@ Page language="c#" Codebehind="down1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.down1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>down1</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="JavaScript">
<!--
//以XML求取数据
//参数:
//obj,当前动作的下拉框
//fullName:要填充的下拉框
function XmlPost(obj,fullName)
{
//求取当前下拉框的值
var svalue = obj.value;
//定义要填充的对象
var fullObj = document.all(fullName);
//定义取值地址
var webFileUrl = "?sortid=" + svalue;
//定义返回值
var result = "";
//开始取值过程
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText; //如果有取到值,则根据格式进行拆分
//注意如果选择了第一行"请选择"空行时,是取不到值的,因此多加了一个条件
if(result != "" && svalue != "")
{
//先清空原有的值
fullObj.length=0;
//拆分值成数组
var piArray = result.split(",");
//循环数组
for(var i=0;i<piArray.length;i++)
{
//再拆分成ID及名称
var ary1 = piArray[i].toString().split("|");
//逐一添加项
fullObj.options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
//如果没有取到值,则清空要填充的下拉框的值
fullObj.length = 0;
fullObj.options.add(new Option("请选择",""));
}
}
//-->
</SCRIPT>
</HEAD>
<body>
<FONT face="宋体">
<form id="Form1" method="post" runat="server">
分类
<asp:DropDownList id="mydown1" runat="server" Width="112px"></asp:DropDownList>
名称
<asp:DropDownList id="mydown2" runat="server" Width="168px"></asp:DropDownList>
</form>
</FONT>
</body>
</HTML>以下为后台代码
-------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebApplication1
{
/// <summary>
/// down1 的摘要说明。
/// 本页面实现了一个完整的二级联动下拉框示例
/// </summary>
public class down1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.DropDownList mydown1;
protected System.Web.UI.WebControls.DropDownList mydown2;
private System.Data.OleDb.OleDbConnection conn; /// <summary>
/// 根据SQL语句返回数据集DataTable
/// </summary>
/// <param name="sql">要产生数据集的SQL语句</param>
/// <returns>返回DataTable</returns>
private DataTable Get_Dt(string sql)
{
//数据库连接串,本数据库为ACCESS数据库,当前在本目录的根目录下
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("data1.mdb") +";";
this.conn = new OleDbConnection(connString);
//打开数据库
this.conn.Open();
OleDbDataAdapter myAdp = new OleDbDataAdapter(sql, this.conn);
DataTable myDt = new DataTable();
try
{
//填充数据
myAdp.Fill(myDt);
//返回数据集
return(myDt);
}
catch(OleDbException ex)
{
//显示错误信息
throw ex;
}
finally
{
//关闭数据库连接
this.conn.Close();
}
} /// <summary>
/// 页面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Page_Load(object sender, System.EventArgs e)
{
//接收参数
string sortid = this.Request.QueryString["sortid"];
//判断参数是否为空(注意:空有两种形式,一种为null,一种为空)
if(sortid + "a" != "a")
{
//如果有传递上述参数,则表示联动操作开始
this.xmlBind(sortid);
} //在页面初次加载的时候,绑定第一/二个下拉框,第二个下拉框为所有值
//但实际上,第二个下拉框应显示空值,因为所有值可能也不少,最好只显示一个"请选择"字样
if(!this.IsPostBack)
{
this.DownBind1();
this.DownBind2();
}
} /// <summary>
/// 返回第2个下拉框需要的值给xmlhttp
/// </summary>
/// <param name="sortid">传递的关键ID值</param>
private void xmlBind(string sortid)
{
string mystr = "";
string sql = "select typename,typeid from class_2 where sortid = " + sortid ;
DataTable mytab = this.Get_Dt(sql); //将取到的值形成: ID|名称,ID|名称...这样的形式
if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i]["typeid"].ToString() + "|" + mytab.Rows[i]["typename"].ToString();
}
mystr = mystr.Substring(1);
} //输出页面
this.Response.Write(mystr);
this.Response.End();
} /// <summary>
/// 绑定第一个下拉框
/// </summary>
private void DownBind1()
{
//显示所有的主分类
string sql = "select sortid,sort from class_1 order by sortid asc ";
DataTable mytab = this.Get_Dt(sql); //绑定第一个下拉框
this.mydown1.DataSource = mytab;
this.mydown1.DataValueField = "sortid";
this.mydown1.DataTextField = "sort";
this.mydown1.DataBind(); //添加一个"请选择"行
this.mydown1.Items.Insert(0,new ListItem("请选择分类","")); //为此下拉框添加一个默认选择项(此处默认为sortid = 1
//做选项时,如果你添加的选定项而此控件中却没有此项,即会出错
//如:this.mydown1.SelectedValue = "1";
//所以此处以如下方式进行选定
ListItem myItem = this.mydown1.Items.FindByValue("1");
if(myItem != null)
{
myItem.Selected = true;
} //为此下拉框添加选择事件,第一个参数是自己,第二个参数为要填充的下拉框的名称
this.mydown1.Attributes.Add("onchange","XmlPost(this,'" + this.mydown2.ClientID + "');");
}
/// <summary>
/// 绑定第二个下拉框
/// </summary>
private void DownBind2()
{
//默认显示分类号为1的所有子类
string sql = "select sortid,typename,typeid from class_2 where sortid =1" ;
DataTable mytab = this.Get_Dt(sql); //绑牢控件
this.mydown2.DataSource = mytab;
this.mydown2.DataSource = mytab;
this.mydown2.DataValueField = "typeid";
this.mydown2.DataTextField = "typename";
this.mydown2.DataBind(); //添加一个空的首行
this.mydown2.Items.Insert(0,new ListItem("请选择名称",""));
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
都要在VS里面做啊??我初学,概念不是很清晰,,仍然习惯在DW里面写asp代码。。其实我这一段时间用VS,感觉是比DW好多了。。(界面除外
id号 名称
sortid sortclass_2
id号 名称 关联号
typeid typename sortid非常感谢 hchxxzx(NET?摸到一点门槛)