# private void Page_Load(object sender, System.EventArgs e)
# {
# // The departmentIndex parameter is added to the query string when
# // a department link is clicked. You need this because when the
# // page is reloaded, the DataList forgets which link was clicked.
# string listIndex = Request.QueryString("departmentIndex");
#
# // If listIndex has a value, this tells you that the visitor
# // has clicked a department, and you inform the DataList about that
# // (so it can apply the correct template for the selected item)
# if ((listIndex != null)) {
# list.SelectedIndex = (int)listIndex;
# }
# //Create a new catalog object
# Catalog catalog = new Catalog();
# // GetDepartments returns a SqlDataReader object that has
# // two fields: DepartmentID and Name. These fields are read in
# // the SelectedItemTemplate and ItemTemplate of the DataList
# list.DataSource = Catalog.GetDepartments();
#
# // Needed to bind the child controls (the HyperLink controls)
# // to the data source
# list.DataBind();
# }
# {
# // The departmentIndex parameter is added to the query string when
# // a department link is clicked. You need this because when the
# // page is reloaded, the DataList forgets which link was clicked.
# string listIndex = Request.QueryString("departmentIndex");
#
# // If listIndex has a value, this tells you that the visitor
# // has clicked a department, and you inform the DataList about that
# // (so it can apply the correct template for the selected item)
# if ((listIndex != null)) {
# list.SelectedIndex = (int)listIndex;
# }
# //Create a new catalog object
# Catalog catalog = new Catalog();
# // GetDepartments returns a SqlDataReader object that has
# // two fields: DepartmentID and Name. These fields are read in
# // the SelectedItemTemplate and ItemTemplate of the DataList
# list.DataSource = Catalog.GetDepartments();
#
# // Needed to bind the child controls (the HyperLink controls)
# // to the data source
# list.DataBind();
# }
{
// The departmentIndex parameter is added to the query string when
// a department link is clicked. You need this because when the
// page is reloaded, the DataList forgets which link was clicked.
string listIndex = Request.QueryString("departmentIndex");
// If listIndex has a value, this tells you that the visitor
// has clicked a department, and you inform the DataList about that
// (so it can apply the correct template for the selected item)
if (listIndex != null)
{
list.SelectedIndex = Convert.ToInt32(listIndex);
}
//Create a new catalog object
Catalog catalog = new Catalog();
// GetDepartments returns a SqlDataReader object that has
// two fields: DepartmentID and Name. These fields are read in
// the SelectedItemTemplate and ItemTemplate of the DataList
list.DataSource = Catalog.GetDepartments();
// Needed to bind the child controls (the HyperLink controls)
// to the data source
list.DataBind();
}初学者多看看书,学会使用MSDN和搜索引擎,有问题自己多思考下
错误 3 “System.Web.HttpRequest.QueryString”是“属性”,但此处被当做“方法”来使用 D:\MyESite\CommerceSite\UserControls\DepartmentsList.ascx.cs 19 36 D:\MyESite\CommerceSite\
错误 4 找不到类型或命名空间名称“Catalog”(是否缺少 using 指令或程序集引用?) D:\MyESite\CommerceSite\UserControls\DepartmentsList.ascx.cs 29 9 D:\MyESite\CommerceSite\
错误 5 找不到类型或命名空间名称“Catalog”(是否缺少 using 指令或程序集引用?) D:\MyESite\CommerceSite\UserControls\DepartmentsList.ascx.cs 29 31 D:\MyESite\CommerceSite\
错误 6 当前上下文中不存在名称“Catalog” D:\MyESite\CommerceSite\UserControls\DepartmentsList.ascx.cs 33 27 D:\MyESite\CommerceSite\
是不是跟我前面有些网页的代码写错了,才会影响到后面的
[]里可用数字和名称
--------------------------------------
他这里的catalog是一个类名!你的程序里面没有当然会报错了!!list.DataSource = Catalog.GetDepartments();
------------------------------------------------------
其实他是返回一个dataset之类的数据集.你自己重新绑定一下吧!
前面我已经定义了一个类Catalog,在它里面我还加了一个Departments函数,是用来连接数据库,并调用GetDepartments存储过程获取数据库信息的.要是我在函数头加上using Catalog ,其他所有的错误就没有了,就只有using Catalog错误,说:找不到类型或命名空间名称“Catalog”(是否缺少 using 指令或程序集引用?),这会是什么原因呢?