2011-05-02 8 views
0

aspx 응용 프로그램이 있습니다. .aspx 파일에 드롭 다운 목록을 정의하고 .aspx.cs 파일의 데이터베이스에서 일부 데이터를로드하려고 시도합니다. 그러나 "DropDownList1"이 현재 컨텍스트에 존재하지 않으므로 .aspx.cs에서 오류가 발생합니다.DropDownList1이 현재 컨텍스트 오류에 없습니다.

Wiki.aspx :

<%@ 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 : 가능한 이유가 될 수 무엇

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 
    } 

} 

아래

는 코드입니다. 나에 따르면 나는 다른 응용 프로그램에 목록 상자에 대해 동일한 방법을 사용 했으므로 모든 것이 훌륭하다고 생각합니다.

+0

웹 응용 프로그램 프로젝트에 "모델"과 "컨트롤러"가 있습니까? – IrishChieftain

+0

왜 그런 일이 발생하지는 않았지만 응용 프로그램을 처음부터 다시 만들었지 만 제대로 작동하지 않았습니다 ... 감사합니다 –

+0

_Wiki.designer.cs 파일의 문제처럼 보입니다. 직접 열고 DropDownlist를 수동으로 추가하십시오 –

답변

1

우연히 다른 파일과 동일한 (부분) Mlass를 상속하거나 정의하려고 시도한 파일이 없는지 확인하십시오.

따라서 파일 뒤에있는 다른 코드는 FinalProj2 네임 스페이스에 같은 서명이 있어야합니다. public partial class _Wiki : System.Web.UI.Page

관련 문제