我正在尝试在以前存在的网站中开始使用 DynamicData 功能。基本上我正在关注本教程。当我谈到创建字段模板的部分时,我决定我可以创建一个内置动态数据内容的新站点,然后将文件夹复制过来。
不幸的是,当我这样做并尝试编译时,对于 DynamicData 目录中的几乎每个 .ascx 文件,我都会收到错误“无法加载类型...”。我将“新”项目命名为与先前存在的站点相同,以便名称空间相同......但我想不出还有什么我可能会丢失。
一切看起来都很好,除了 *.ascx.Designer.cs 文件显示在解决方案资源管理器中。我尝试删除一个,然后将该文件复制回目录,但它没有用。我假设我需要对那些做一些特别的事情,以便 Visual Studio 正确处理它们并可以编译?
这是 .aspx 文件之一:
<%@ Control Language="C#" CodeBehind="FilterUserControl.ascx.cs" Inherits="EService.FilterUserControl" %>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
EnableViewState="true" ontextchanged="new">
<asp:ListItem Text="All" Value="" />
</asp:DropDownList>
这是匹配的 .cs 文件:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
namespace EService
{
public partial class FilterUserControl : System.Web.DynamicData.FilterUserControlBase
{
public event EventHandler SelectedIndexChanged
{
add
{
DropDownList1.SelectedIndexChanged += value;
}
remove
{
DropDownList1.SelectedIndexChanged -= value;
}
}
public override string SelectedValue
{
get
{
return DropDownList1.SelectedValue;
}
}
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateListControl(DropDownList1);
// Set the initial value if there is one
if (!String.IsNullOrEmpty(InitialValue))
DropDownList1.SelectedValue = InitialValue;
}
}
}
}
这是 .ascx.designer.cs 文件:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace EService
{
public partial class FilterUserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
}
}
编辑:如果我在网站中创建文件,然后从我创建的临时网站复制内容,它似乎编译得很好。真的不知道这里的问题是什么......我尝试手动修改文件以匹配复制的结果,除非我实际在站点中创建它们,否则它们仍然无法工作。真是奇怪……