Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Abbreviatting large text fields with an ellipsis

Abbreviatting large text fields with an ellipsis

Scheduled Pinned Locked Moved Database
questiondatabaseperformance
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neophyte30
    wrote on last edited by
    #1

    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...

    C M 2 Replies Last reply
    0
    • N Neophyte30

      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...

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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 |

      N 3 Replies Last reply
      0
      • C Colin Angus Mackay

        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 |

        N Offline
        N Offline
        Neophyte30
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • C Colin Angus Mackay

          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 |

          N Offline
          N Offline
          Neophyte30
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          • C Colin Angus Mackay

            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 |

            N Offline
            N Offline
            Neophyte30
            wrote on last edited by
            #5

            CASE WHEN LEN(description) > 71 THEN SUBSTRING(description,0,CHARINDEX(' ',description,70))+'...' ELSE '' END AS tooltip, Got it - thanks again.

            1 Reply Last reply
            0
            • N Neophyte30

              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...

              M Offline
              M Offline
              Mark Churchill
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups