Hi anybody know how to use databinder.eval in c#
Actually I've tried this
LinkButton lnkName = new LinkButton();
lnkName.CommandArgument = DataBinder.Eval("object","<%#COURSE_ID%>");
it is showing error. Whats the wrong with this?
You can't use Eval in the code behind of an aspx page.
this:
lnkName.CommandArgument = DataBinder.Eval("object","<%#COURSE_ID%>");
should be this:
lnkName.CommandArgument = YOUR_OBJECT_PROPERTY_HERE;
To fill in YOUR_OBJECT_PROPERTY_HERE you either need to specify the object.property etc like normal in C# code, or you'll have to use reflection to get the property value from the object (which is what eval does for you).
Here is a link showing how to use reflection to get the property information from an object. You can use it to duplicate how eval works if you need to: https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6099345.html
Link to DataBinder Eval Method: http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx
How the DataBinder Eval Method works (and why the author thinks it should be avoided) http://weblogs.asp.net/jgalloway/archive/2005/09/20/425687.aspx