I don't like a lot of logic in my view, and this sort of thing is useful all over (not just in views).
<option value="<%=order.ID %>"><%=order.Item.Truncate(10) %></option>
And the Truncate method...
public static class StringExtensions
{
public static string Truncate(this string value, int trim)
{
//Don't do anything if the value is null, empty, or doesn't meet our trim constraint
if (string.IsNullOrEmpty(value) || value.Length <= trim)
{
return value;
}
return string.Format("{0}...", value.Substring(0, trim));
}
}
Caveat:
I haven't trimmed the length of the ellipsis off. If you want to, you should do some additional checking to ensure that (trim-3) is greater than zero Also, you should look at accounting for whether the trim length is greater than the length of the string. I would do, but my brain is shutting down for the night!