0

几天来,我在 ASP.NET 中遇到了一个项目问题。我应该设计一个网站:

  • 第一:检查项目文件夹中是否为子文件夹 bin 以及此 bin 文件夹中是否存在两个特定文件之一的函数
  • 第二:一个功能(列表),它会在网站上只显示具有第一个功能条件的文件夹

现在来解决问题。在一些帮助下,我设法编写了代码(顺便说一句,我是 ASP.NET 的新手)。这是代码:

这里是aspx代码:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Home.aspx.cs" Inherits="TestSite.Home" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <link href="Layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ListView ID="listView" runat="server"> 
        <ItemTemplate> 
            <asp:Label ID="Label1" Text="<%#Container.DataItem %>" runat="server" /> 
        </ItemTemplate> 
    </asp:ListView>
</div>
</form>
</body>
</html>

这是 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.IO;

namespace TestSite
{
public partial class WorkingwithDirectory : System.Web.UI.Page
{           
    List<string> results = new List<string>();

    public bool IsApplicationDirectory( string directory )
    {
        if ( Directory.Exists(Server.MapPath("~/../bin")) ) {
            if ( File.Exists(Server.MapPath("~/../bin/Portal.Server.dll")) || File.Exists(Server.MapPath("~/../bin/Host.Server.dll")) ) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }

    public List<string> GetApplicationDirectories()
    {


        DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/"));
        foreach (DirectoryInfo di in dir.GetDirectories())
        {
            if ( IsApplicationDirectory( dir.FullName ) ) 
            {
                results.Add(dir.FullName);
            }
        }
        return results;
    }

    protected void Page_Load( object sender, EventArgs e )
    {

        if ( !Page.IsPostBack ) 
        {
            List<string> appDirectories = GetApplicationDirectories();

            --> listView.DataSource = appDirectories;
            --> listView.DataBind();
        }
    }
}

}

问题:在上面的 aspx.cs 文件中(我在其中给出了箭头)我收到一条错误消息,告诉我:“当前上下文中不存在名称 'listView'”

我尝试了一些解决方案,但不幸的是没有一个主题有效。我会更感谢您的帮助。

4

1 回答 1

0

改名

public partial class WorkingwithDirectory : System.Web.UI.Page

public partial class Home : System.Web.UI.Page
于 2013-10-08T10:48:08.523 回答