I would suggest an extension method for heavy lifting to make markup as simple as possible:
public static string EvalTrimmed(this RepeaterItem container, string expression, int maxLength)
{
string value = DataBinder.Eval(container, expression) as string;
if ( value != null )
return null;
if (value.Length > maxLength)
value = value.Substring(0,maxLength) + "...";
return value;
}
Then use it in markup like:
<%# Container.EvalTrimmed("DataItem.Title", 20) %>
driis source
share