为什么我的ASP.NET FormView总是呈现EmptyTemplate
本文关键字:EmptyTemplate FormView 我的 ASP NET 为什么 | 更新日期: 2023-09-27 18:28:10
我有一个FormView绑定到一个放置在用户控件内的ObjectDataSource,用以下代码初始化:
<asp:ObjectDataSource ID="odsCampaign" runat="server"
DataObjectTypeName="code.model.Campaign"
TypeName="code.model.Campaign"
SelectMethod="LoadCampaign">
<SelectParameters>
<asp:QueryStringParameter Name="code" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- ... --%>
<asp:FormView ID="fvCampaign" runat="server"
DataSourceID="odsCampaign">
<EmptyDataTemplate>
<span>No campaign loaded.</span>
</EmptyDataTemplate>
<ItemTemplate>
<span>Campaign</span>
<span><%# Eval("Subject") %></span>
<%-- ... --%>
</ItemTemplate>
</asp:FormView>
我后面的代码看起来像这样:
// CampaignCallCollection inherits from IEnumerable<CampaignCall>
public class Campaign : CampaignCallCollection
{
// Some property to show
public string Subject { get; set; }
// Constructor
public Campaign(int code)
: base()
{
// Initialize the object based on the primary key passed to the constructor
InitializeCampaign(code);
}
private void InitializeCampaign(int code)
{
// Initialization Code
}
// Loading method for ObjectDataSource
public static Campaign LoadCampaign(int code)
{
// Return new instance of an initialized campaign object.
Campaign oCampaign = new Campaign(code);
//throw new Exception(oCampaign.Subject);
return oCampaign;
}
}
但是,如果我启用了异常,则正确的主题文本将作为异常消息传递。但是我的FormView在所有方面都渲染EmptyTemplate。我真的不认为这里有错。有人能帮我吗?
提前感谢!
是因为它需要一个活动列表而不是单个活动吗?