http://www.dotnetspider.com/technology/KBPages/964.aspx
Imports System.Web.UI.WebControls
Public Class LimitColumn Inherits BoundColumn
Public CharacterLimit As Integer = 0 Protected Overrides Function FormatDataValue(ByVal dataValue As Object) As String Return Truncate(dataValue.ToString(), CharacterLimit) End Function Public Function Truncate(ByVal input As String, ByVal characterLimit As Integer) As String Dim output As String = input
' Check if the string is longer than the allowed amount ' otherwise do nothing If output.Length > characterLimit And characterLimit > 0 Then ' cut the string down to the maximum number of characters output = output.Substring(0, characterLimit) ' Check if the character right after the truncate point was a space ' if not, we are in the middle of a word and need to remove the rest of it If input.Substring(output.Length, 1) <> " " Then Dim LastSpace As Integer = output.LastIndexOf(" ") ' if we found a space then, cut back to that space If LastSpace <> -1 Then output = output.Substring(0, LastSpace) End If End If ' Finally, add the "...", telling user that there is more text output += "..." End If Return output End Function End Class
|
| Author: Asar Imhotep 31 Oct 2005 | Member Level: Bronze Points : 0 |
Is there an actual page I can see the full code? It seems not to be working and I don't know if I am putting the code in the right place. I am using VB. Can someone help me out? Thanks in advance.
|