【问题标题】:Debugging CS0103 Error in Visual Studio code调试 Visual Studio 代码中的 CS0103 错误
【发布时间】:2022-01-25 10:51:39
【问题描述】:

您好,我正在创建一个下拉列表并以编程方式从后面的代码中插入值,但是我反复收到错误 CS0103。然而,我的程序和网页运行完全正常,但它只是困扰我,想知道是否有办法抑制这些错误消息,或者我可能遗漏了什么。

错误:CS0103 当前上下文中不存在名称“ddlzip”

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace bse20bftmoviestore.tutorials.week3
{
    public partial class formSample : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)//When page is loaded everytime
        {
  
            txtFname.Focus();
            
            if (!Page.IsPostBack)//When page is first loaded
            {
                //Code behind to create items in the dropdown
                ListItem li1 = new ListItem("Select zip code", "-1");
                ListItem li2 = new ListItem("1111", "1");
                ListItem li3 = new ListItem("2222", "2");
                ListItem li4 = new ListItem("3333", "3");
                ddlzip.Items.Add(li1);
                ddlzip.Items.Add(li2);
                ddlzip.Items.Add(li3);
                ddlzip.Items.Add(li4);

            }
        }
    }
}

我在网络表单中的下拉列表:

<!--zip code title and dropdown list (programmatically defined)-->
                <div class="form-group row justify-content-center">
                   <asp:Label runat="server" CssClass="col-md-2 col-form-label">Zip Code</asp:Label>
                      <div class="col-md-8">
                          <asp:DropDownList ID="ddlzip" CssClass="form-control" runat="server"></asp:DropDownList>
                      </div>
                </div>
<!--End of zip code title and dropdown list (programmatically defined)-->

错误:CS0103 当前上下文中不存在名称“ddlzip”

【问题讨论】:

  • 你检查过herehere吗?
  • 我在代码中没有看到您定义 ddlZip 的位置?

标签: c# asp.net visual-studio web-applications


【解决方案1】:

这个问题的解决方案是在 .aspx 页面标题中链接 CodeFile 和 CodeBehind。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

有时会关闭然后重新打开解决方案工作。 另一个解决方案是删除 bin 和 obj 文件夹并再次构建项目。 这些解决方案对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 2021-05-16
    • 1970-01-01
    • 2016-07-13
    • 2019-08-20
    • 1970-01-01
    相关资源
    最近更新 更多