0

I have textbox "Description". This values are stored in database and retrieve to show the details page like,

Description

Here, Description is there. But there is something more thn 1000 characters they enter and store. It is not prominent to display all characters. so i want to show first line of the description only.

My view is:

<div class="fourth-line">
            Description: <%:item.Description %>
         </div>

Here, how will limit the characters?any idea?

4

1 回答 1

1

Basically you have two options, to truncate the value on the server or hide part of the value on the client.

To truncate string on the server you can do something like this:

    Description: <%: 
                     item.Description.IndexOf("\n") > 0 
                     ? String.Format("{0}..", item.Description.Substring(0, 
                       item.Description.IndexOf("\n"))
                     : item.Description
                 %>

Or on the client, apply the ellipsis class

<div class="fourth-line ellipsis">
   Description: <%:item.Description %>
</div>

which could look like:

.ellipsis {
   white-space: nowrap;
   text-overflow: ellipsis; 
}
于 2013-05-30T11:28:18.003 回答