First 150 characters..
Hi,
Anyone know how to add a field to a widget template so that it pulls only the first few characters of the field? For example, we have a custom module that has Questions and Answers. I want to the master view to have a list of the questions with the first part of the answer.
I tried
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text='<%# Eval("Answer").ToString().Substring(0,Math.Min(150,Eval("Answer").ToString().Length)) + "…" %>'></
asp:Label
>
Sitefinity has an extension method to truncate
Class is SitefinityExtensions
public
static
string
TruncateString(
this
string
valueToTruncate,
int
maxLength, SitefinityExtensions.TruncateOptions options)
That's exactly what I needed. Thanks so much Steve!
Np, FYI...truncateoptions has 4 modes...I think they can stack (marked as flags)
None
FinishWord
AllowLastWordToGoOverMaxLength
IncludeEllipsis