I've got an FormView bound to an ObjectDataSource placed inside an usercontrol, initialized with the following code:
<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>
My code behind looks something like this:
// 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;
}
}
However if I enable the exception the proper subject text is passed as exception message. But my FormView does allways render the EmptyTemplate. I do not really see mistake in here. Can anyone help me out with this?
Thanks in advance!
Is it because it is expecting a list of Campaigns not an individual Campaign?