Asp.net 当前上下文错误中不存在DropDownList1
我有一个aspx应用程序。我在.aspx文件中定义了一个dropdownlist,并尝试从.aspx.cs文件中的数据库将一些数据加载到其中。但是我在.aspx.cs中得到了错误,因为DropDownList1在当前上下文中不存在 代码如下: Wiki.aspx:Asp.net 当前上下文错误中不存在DropDownList1,asp.net,drop-down-menu,Asp.net,Drop Down Menu,我有一个aspx应用程序。我在.aspx文件中定义了一个dropdownlist,并尝试从.aspx.cs文件中的数据库将一些数据加载到其中。但是我在.aspx.cs中得到了错误,因为DropDownList1在当前上下文中不存在 代码如下: Wiki.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Wiki.aspx.cs" Inherits="FinalProj2._Wiki" %> <!DOCT
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Wiki.aspx.cs" Inherits="FinalProj2._Wiki" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body { margin: 4%; }
#space1 { height:1em; }
#space2 { height:1em; }
</style>
</head>
<body>
<h1>WIKI</h1>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Width="100%"></asp:DropDownList>
</div>
<div id="space1"></div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack = "true" Height = "150px" Width = "100%"></asp:ListBox>
<div id="space2"></div>
<asp:TextBox ID="TextBox2" runat="server" Height="250px" Width="100%" TextMode="MultiLine"></asp:TextBox>
</form>
</body>
</html>
Wiki.aspx.cs:
可能的原因是什么。根据我的说法,我觉得一切都很好,就像在另一个应用程序中使用列表框一样。确保没有文件意外地试图继承或定义与其他文件相同的部分Mlass 因此,在FinalProj2名称空间中,其他代码隐藏文件不应具有相同的签名。
公共分部类_Wiki:System.Web.UI.Page确保没有文件意外尝试继承或定义与其他文件相同的分部类 因此,在FinalProj2名称空间中,其他代码隐藏文件不应具有相同的签名。
公共部分类_Wiki:System.Web.UI.Page只是好奇,您在Web应用程序项目中有模型和控制器吗?我不知道为什么会发生这种情况,但我重新创建了应用程序,但它没有工作。。。ThanksIt在_Wiki.designer.cs文件中看起来像问题。打开它并手动添加DropDownList只是好奇,您在Web应用程序项目中有模型和控制器?我不知道为什么会发生这种情况,但我重新创建了应用程序,但它没有工作。。。ThanksIt在_Wiki.designer.cs文件中看起来像问题。打开它并手动添加DropDownlist
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FinalProj2.Controllers;
namespace FinalProj2
{
public partial class _Wiki : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FinalProj2.Models.DataClasses1DataContext db = new FinalProj2.Models.DataClasses1DataContext();
Response.Write("<br/>Page.User.Identity.Name: " + Page.User.Identity.Name);
Response.Write("<br/>Page.User.Identity.IsAuthenticated: " + Page.User.Identity.IsAuthenticated);
Response.Write("<br/>Page.User.Identity.AuthenticationType: " + Page.User.Identity.AuthenticationType);
var query = from meet in db.Meets
select meet.Summary;
// where meet.Meeting_ID = (from meet_emp in db.Meet_Emps
//where meet_emp.Employee_Name == Page.User.Identity.Name
//select meet_emp.Meeting_ID)
DropDownList1.DataSource = query;
DropDownList1.DataBind();
}//end
}
}