Last post Jan 29, 2008 01:37 AM by Nai-Dong Jin - MSFT
Jan 25, 2008 03:01 PM|snives|LINK
Hopefully this is something simple.
I built a simple templated databound webcontrol similar to the one in the quickstarts tutorial here.
as well as
The error is: "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."
My guess is that Eval(), being a method of TemplateControl, somehow doesn't know it is databound. Has anyone ran across this before?
Jan 29, 2008 01:37 AM|Nai-Dong Jin - MSFT|LINK
From you description, it seems that you are binding data to a simple control, right?
You cannot use the use EVAL() method with a simple databinding controls. It has to be with an IBindingList or IList typed controls, like GridView, ListView, etc. The container should be Container.DataItem by default, so you can just call Eval(“Expression”).
Otherwise, you have to specify the object which references the expression that is evaluated explicitly. (e.g: <%# DataBinder.Eval(Container.DataItem, "FirstName") %> )
For more details on DataBinder.Eval Method (Object, String), see: