jgd1234567
Programmer
Hi, i'm trying to add no data template to the repeater control. I am following the article at:
Basically i add a property to the repeater:
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate EmptyDataTemplate
{
get { return _emptyDataTemplate; }
set { _emptyDataTemplate = value; }
}
The article suggests to override the OnDataBinding event with:
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (this.Items.Count == 0 && this.EmptyDataTemplate != null)
{
this.EmptyDataTemplate.InstantiateIn(this);
}
}
but this still renders the header and footer and i believe since it executed on the OnDataBinding event it won't be carried out if a postback is made.
Therefore i decided to move it to the render event:
protected override void Render(HtmlTextWriter writer)
{
if (this.Items.Count == 0 && this.EmptyDataTemplate != null)
this.EmptyDataTemplate.InstantiateIn(this);
else
base.Render(writer);
}
However it doesn't write the template to the page. If i simply put:
protected override void Render(HtmlTextWriter writer)
{
if (this.Items.Count == 0 && this.EmptyDataTemplate != null)
writer.Write("No data");
else
base.Render(writer);
}
The string no data is displayed correctly when there is no data but obviously this hasn't taken advantage of my template.
Appreciate if someone could tell me how i could write my template property in the Render method. Sorry if this is really easy but i'm new to template properties and i can't find any help on this.
Thanks
Basically i add a property to the repeater:
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate EmptyDataTemplate
{
get { return _emptyDataTemplate; }
set { _emptyDataTemplate = value; }
}
The article suggests to override the OnDataBinding event with:
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (this.Items.Count == 0 && this.EmptyDataTemplate != null)
{
this.EmptyDataTemplate.InstantiateIn(this);
}
}
but this still renders the header and footer and i believe since it executed on the OnDataBinding event it won't be carried out if a postback is made.
Therefore i decided to move it to the render event:
protected override void Render(HtmlTextWriter writer)
{
if (this.Items.Count == 0 && this.EmptyDataTemplate != null)
this.EmptyDataTemplate.InstantiateIn(this);
else
base.Render(writer);
}
However it doesn't write the template to the page. If i simply put:
protected override void Render(HtmlTextWriter writer)
{
if (this.Items.Count == 0 && this.EmptyDataTemplate != null)
writer.Write("No data");
else
base.Render(writer);
}
The string no data is displayed correctly when there is no data but obviously this hasn't taken advantage of my template.
Appreciate if someone could tell me how i could write my template property in the Render method. Sorry if this is really easy but i'm new to template properties and i can't find any help on this.
Thanks