嗨,我正在創建一個下拉串列并從后面的代碼中以編程方式插入值,但是我反復收到錯誤 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”
uj5u.com熱心網友回復:
有時關閉然后重新打開解決方案作業。另一個解決方案是洗掉 bin 和 obj 檔案夾并再次構建專案。這些解決方案對我有用
uj5u.com熱心網友回復:
這個問題的解決方案是在 .aspx 頁面標題中鏈接 CodeFile 和 CodeBehind。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/396896.html
上一篇:按當月獲取記錄的問題
