从代码隐藏访问下拉列表
我有一个 .aspx 文件,其中有 3 个下拉列表: ddlMake ddl模型 ddlColour
我有一个 Page_Load 函数,但我无法在 Page_Load 函数中访问它们...
using System;
using System.Collections.Generic;
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;
namespace NorthwindCascading
{
public partial class _IndexBasic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CarService service = new CarService();
List<string> Makes = service.GetCarMakes();
ddlMake.DataSource = Makes;
ddlMake.DataBind();
ddlMake.Items.Insert(0, " -- Select Make -- ");
}
}
}
}
我已经手动添加了代码隐藏文件,所以我想我错过了一些东西...它只是说 ddlMake 元素未在当前上下文中定义...有什么建议吗?
I have an .aspx file that has 3 drop down lists:
ddlMake
ddlModel
ddlColour
i have a Page_Load function but i cant acces them in the Page_Load function...
using System;
using System.Collections.Generic;
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;
namespace NorthwindCascading
{
public partial class _IndexBasic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CarService service = new CarService();
List<string> Makes = service.GetCarMakes();
ddlMake.DataSource = Makes;
ddlMake.DataBind();
ddlMake.Items.Insert(0, " -- Select Make -- ");
}
}
}
}
I have added the code-behind file manually so i guess i am missing something... it just says that the ddlMake
element is not defined in current context...any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
而不是弄清楚哪里出了问题。我建议您只需删除该文件并重新执行您所做的操作即可。会节省您的时间......
Rather than figure out what went wrong. I suggest you just simply delete the file and re-do what you have done again. Will save your time....
确保页面指令中的 CodeFile/CodeBehind 属性指向正确的文件。如果是这样,请确保页面指令中的 Inherits 属性命名了正确的类名。
Make sure your CodeFile/CodeBehind attribute in the page directive is pointing to the correct file. If so, make sure the Inherits attribute in the page directive is naming the correct class name.
如果您手动添加后面的代码,则
_IndexBasic.designer.cs
可能不包含protected
成员,这就是您在此处看不到它们的原因。或者,您的 aspx 没有将其引用为您的代码隐藏。If you added the code behind manually, then the
_IndexBasic.designer.cs
probably doesn't contain theprotected
members, which would be why you cannot see them here. Or, your aspx is not referencing this as your codebehind.右键单击 .aspx 页面并点击
转换为 Web 应用程序
- 这将创建并填充设计器文件。Right-click on your .aspx page and hit
Convert to Web Application
- that will create and populate the designer file.