从代码隐藏访问下拉列表

发布于 2024-10-06 20:12:59 字数 987 浏览 5 评论 0原文

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蝶…霜飞 2024-10-13 20:12:59

而不是弄清楚哪里出了问题。我建议您只需删除该文件并重新执行您所做的操作即可。会节省您的时间......

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....

走过海棠暮 2024-10-13 20:12:59

确保页面指令中的 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.

蓝海 2024-10-13 20:12:59

如果您手动添加后面的代码,则 _IndexBasic.designer.cs 可能不包含 protected 成员,这就是您在此处看不到它们的原因。或者,您的 aspx 没有将其引用为您的代码隐藏。

If you added the code behind manually, then the _IndexBasic.designer.cs probably doesn't contain the protected members, which would be why you cannot see them here. Or, your aspx is not referencing this as your codebehind.

梦里南柯 2024-10-13 20:12:59

右键单击 .aspx 页面并点击转换为 Web 应用程序 - 这将创建并填充设计器文件。

Right-click on your .aspx page and hit Convert to Web Application - that will create and populate the designer file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文