jgd1234567
Programmer
Hi, i have created my own custom repeater which inherits from the standard repeater and the only difference is that it contains an EmptyDataTemplate.
public class Repeater : System.Web.UI.WebControls.Repeater
{
private ITemplate _emptyDataTemplate;
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate EmptyDataTemplate
{
get { return _emptyDataTemplate; }
set { _emptyDataTemplate = value; }
}
protected override void OnPreRender(EventArgs e)
{
// If there is no data then we don't wish to render anything (including the header and the footer)
if (this.Items.Count == 0)
{
// If an empty data template has been provided then display it
if (this.EmptyDataTemplate != null)
{
Control templateContainer = new Control();
this.EmptyDataTemplate.InstantiateIn(templateContainer);
this.Controls.Add(templateContainer);
}
}
else
base.OnPreRender(e);
}
}
Then on my page i am able to say:
<custom:Repeater ID="rptEvents" runat="server" DataSourceID="objEvents">
<ItemTemplate>
event info
</ItemTemplate>
<EmptyDataTemplate>
<custom:Repeater ID="rptCategories" runat="server" DataSourceID="objCategories">
<ItemTemplate>
category info
</ItemTemplate>
<EmptyDataTemplate>
<p>No events or categories.</p>
</EmptyDataTemplate>
</custom:Repeater>
<asp:ObjectDataSource ID="objCategories" runat="server" SelectMethod="GetCategories" TypeName="Category">
</asp:ObjectDataSource>
</EmptyDataTemplate>
</custom:Repeater>
<asp:ObjectDataSource ID="objEvents" runat="server" SelectMethod="GetEvents" TypeName="Event">
</asp:ObjectDataSource>
However if the outer repeater is empty the inner repeater always renders as if it was empty. I tried replacing the inner repeater with a standard repeater and it rendered fine but this doesn't allow me to have an EmptyDataTemplate for my inner repeater.
Appreciate if someone can help.
Thanks
public class Repeater : System.Web.UI.WebControls.Repeater
{
private ITemplate _emptyDataTemplate;
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate EmptyDataTemplate
{
get { return _emptyDataTemplate; }
set { _emptyDataTemplate = value; }
}
protected override void OnPreRender(EventArgs e)
{
// If there is no data then we don't wish to render anything (including the header and the footer)
if (this.Items.Count == 0)
{
// If an empty data template has been provided then display it
if (this.EmptyDataTemplate != null)
{
Control templateContainer = new Control();
this.EmptyDataTemplate.InstantiateIn(templateContainer);
this.Controls.Add(templateContainer);
}
}
else
base.OnPreRender(e);
}
}
Then on my page i am able to say:
<custom:Repeater ID="rptEvents" runat="server" DataSourceID="objEvents">
<ItemTemplate>
event info
</ItemTemplate>
<EmptyDataTemplate>
<custom:Repeater ID="rptCategories" runat="server" DataSourceID="objCategories">
<ItemTemplate>
category info
</ItemTemplate>
<EmptyDataTemplate>
<p>No events or categories.</p>
</EmptyDataTemplate>
</custom:Repeater>
<asp:ObjectDataSource ID="objCategories" runat="server" SelectMethod="GetCategories" TypeName="Category">
</asp:ObjectDataSource>
</EmptyDataTemplate>
</custom:Repeater>
<asp:ObjectDataSource ID="objEvents" runat="server" SelectMethod="GetEvents" TypeName="Event">
</asp:ObjectDataSource>
However if the outer repeater is empty the inner repeater always renders as if it was empty. I tried replacing the inner repeater with a standard repeater and it rendered fine but this doesn't allow me to have an EmptyDataTemplate for my inner repeater.
Appreciate if someone can help.
Thanks