Hello Andrew
> "InvalidOperationException was unhandled by user code
> Databinding methods such as Eval(), XPath(), and Bind() can only be used
> in
> the context of a databound control."
Look what google says about that error message.
I guess, its for the reason, that your control doesnt represent a databound
control.
Anyway, that should work:
<%#DataBinder.Eval(Container.DataItem, "field").ToString()%>

Signature
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Brook - 18 Mar 2008 16:40 GMT
Thanks Peter - i made the changes and the control no longer throws the error.
In fact the control works in every way i'd expect.
The only thing that i wonder about now, is why my control is different to
say a normal asp:panel. Does an asp:panel perhaps inherit from some classes
that allow child controls to bind to their data sources using Eval?
Afterall, i don't want to bind any data to my control, i want to bind to the
child controls that get added into the controls ITemplate
At the moment, my custom control is inheriting from WebControl, and
implementing INamingContainer
thanks,
Andrew
> Hello Andrew
>
[quoted text clipped - 9 lines]
>
> <%#DataBinder.Eval(Container.DataItem, "field").ToString()%>
Teemu Keiski - 20 Mar 2008 22:40 GMT
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control"
Sounds familiar error to me. ;-)
How's the template's instantiation in the control - regarding how it gets
added to Controls collection? And is template container specified
(TemplateContainer attribute)?

Signature
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
> Hello Andrew
>
[quoted text clipped - 9 lines]
>
> <%#DataBinder.Eval(Container.DataItem, "field").ToString()%>
Brook - 25 Mar 2008 15:55 GMT
Hi - i think this is the code you're interested in seeing :-
private ITemplate _PanelContent;
private PlaceHolder phContent = new PlaceHolder();
[PersistenceMode(PersistenceMode.InnerProperty),
TemplateInstance(TemplateInstance.Single),
TemplateContainer(typeof(TemplateControl))]
public ITemplate Content
{
get { return _PanelContent; }
set { _PanelContent = value; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (_PanelContent != null)
{
_PanelContent.InstantiateIn(phContent);
}
EnsureChildControls();
}
thanks,
Andrew
> "Databinding methods such as Eval(), XPath(), and Bind() can only be used in
> the context of a databound control"
[quoted text clipped - 18 lines]
> >
> > <%#DataBinder.Eval(Container.DataItem, "field").ToString()%>