Abbreviatting large text fields with an ellipsis
-
I am currently optimising an internal intranet site, and I have spotted a possible gain - moving the abbreviation of a text field from the RowDataBound event of a GridView into the SQL stored proc that retrieves the data. My question is - can anyone suggest the best way to choose an appropriate abbreviation point so that the ellipsis is added only after a break in the text? i.e. This is a... rather than This is a te... As I am looking for performance gains, I'll put up with ugly abbreviation if I have to, but it would be nice if there were a [relatively] quick, simple solution to keep it looking pretty...
-
I am currently optimising an internal intranet site, and I have spotted a possible gain - moving the abbreviation of a text field from the RowDataBound event of a GridView into the SQL stored proc that retrieves the data. My question is - can anyone suggest the best way to choose an appropriate abbreviation point so that the ellipsis is added only after a break in the text? i.e. This is a... rather than This is a te... As I am looking for performance gains, I'll put up with ugly abbreviation if I have to, but it would be nice if there were a [relatively] quick, simple solution to keep it looking pretty...
You could create a function to do this by using the string functions already provided by SQL Server[^].
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Creating Many-to-Many Joins * A simple challenge (solution) My website |
-
You could create a function to do this by using the string functions already provided by SQL Server[^].
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Creating Many-to-Many Joins * A simple challenge (solution) My website |
Thanks for the suggestion - I'll give it a go. I guess there's no definitive answer to whether it's faster more efficient to do the abbreviation on the SQL server as opposed to the web-server, what with hardware variables and the like? My thinking was along the lines of avoiding looping algorithms - the c# code is currently doing a split, then adding words back until a limit is reached - in favour of a more set-based operation... Maybe I should just grasp the nettle, and use a fixed length abbreviation...
-
You could create a function to do this by using the string functions already provided by SQL Server[^].
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Creating Many-to-Many Joins * A simple challenge (solution) My website |
OK - halfway there... SUBSTRING(description,0,CHARINDEX(' ',description,70))+'...' AS tooltip Just need to wrap this in a case/if to exclude descriptions shorter than 70 characters... Thanks for the nudge!
-
You could create a function to do this by using the string functions already provided by SQL Server[^].
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Creating Many-to-Many Joins * A simple challenge (solution) My website |
CASE WHEN LEN(description) > 71 THEN SUBSTRING(description,0,CHARINDEX(' ',description,70))+'...' ELSE '' END AS tooltip, Got it - thanks again.
-
I am currently optimising an internal intranet site, and I have spotted a possible gain - moving the abbreviation of a text field from the RowDataBound event of a GridView into the SQL stored proc that retrieves the data. My question is - can anyone suggest the best way to choose an appropriate abbreviation point so that the ellipsis is added only after a break in the text? i.e. This is a... rather than This is a te... As I am looking for performance gains, I'll put up with ugly abbreviation if I have to, but it would be nice if there were a [relatively] quick, simple solution to keep it looking pretty...
You can also do this in a stylesheet if you don't care too much about the bandwidth. The benefits to this approach are that the text is trimmed at the appropriate position as the client lays it out. To be honest I sincerely doubt there is any real gain to be made trimming the string on the database vs in the code behind... (unless we are talking massive amounts of text) ;)
Mark Churchill Director Dunn & Churchill Free Download:
Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.