Imagine that I introduced an extension method on string type called Shorten() which gets only the first 50 characters and returns it.
If I want to call this method on a GridView’s bound field, what is the simplest way of calling it so that on screen I see the shorten version of the message.
<!-- TODO: How to call .Shorten() extension method on the ItemDescription in markup: --!>
<asp:BoundField HeaderText="Items" DataField="ItemDescription"...>
Make that column a template column:
And make sure ToShorten takes an object, not a string since
Evalreturns object.*Above code not tested but pretty sure is very close.
Another alternative:
Modify your class and add a
ItemDescriptionShortenproperty that would be like this:Now bind to that property instead of
ItemDescription