DataBinding logic
-
Is it possible to include some logic betweeb <%%> tags when databinding. What I want is something like the following :
string m =
DataBinder.Eval(Container.DataItem, "modelName").ToString();
if ( m.Length > 20 ) Response.Write(m.Substring(0,20) + "..");
else Response.Write(m);But I get the following error :
Compiler Error Message: CS0103: The name 'Container' does not exist in the current context
TIA. "Do not inflate plain things into marvels, but reduce marvels to plain things." - Francis Bacon
-
Is it possible to include some logic betweeb <%%> tags when databinding. What I want is something like the following :
string m =
DataBinder.Eval(Container.DataItem, "modelName").ToString();
if ( m.Length > 20 ) Response.Write(m.Substring(0,20) + "..");
else Response.Write(m);But I get the following error :
Compiler Error Message: CS0103: The name 'Container' does not exist in the current context
TIA. "Do not inflate plain things into marvels, but reduce marvels to plain things." - Francis Bacon
Create a public function in your code-behind file and then call it as follows (the following is an example from within a datagrid TemplateColumn): <%# MyFunction(Container.DataItem("BlahField")) %> Find my .Net blog at http://hiltong.blogspot.com
-
Create a public function in your code-behind file and then call it as follows (the following is an example from within a datagrid TemplateColumn): <%# MyFunction(Container.DataItem("BlahField")) %> Find my .Net blog at http://hiltong.blogspot.com
Hi Hilton, I did know that and thats what I've been doing but I've had this nagging feeling that there was a cooler way all the gurus where using and I wasn't in on it. But that'll do me, cheers. "Do not inflate plain things into marvels, but reduce marvels to plain things." - Francis Bacon