I want to achive here.. is if STRCONTENT's lenght is more than 40 then it will show "..." at the end..
Like this... "Truly your God is the God of gods, the Lord of kings, and a revealer of secrets, since you could reveal....".
Noticed the "...." at the end...
public static string GetSubString(string text, int maxDescriptionSize = 0)
{
maxDescriptionSize = maxDescriptionSize.Equals(0) ? MaxDescriptionSize : maxDescriptionSize;
if (!string.IsNullOrWhiteSpace(text) && text.Length > maxDescriptionSize)
{
text = string.Concat(text.Substring(0, maxDescriptionSize), "...");
}
return text;
}
And call this function while grid bind.
Kurai
Member
233 Points
182 Posts
How to shorten a field?
Feb 29, 2012 03:29 AM|LINK
Hi,
I am having a problem when the content's length of my STRCONTENT field is too many that it over than my row column's height..
<td style="padding: 4px; width: 192px; height:70px"> <div style="font-weight: normal; color: gray"> <a href="#" id="lnkShowUserMessageModal" class="overshow"> <%#Eval("strContent")%> </a> </div> </td>I want to achive here.. is if STRCONTENT's lenght is more than 40 then it will show "..." at the end..
Like this... "Truly your God is the God of gods, the Lord of kings, and a revealer of secrets, since you could reveal....".
Noticed the "...." at the end...
eval href
karthicks
All-Star
31334 Points
5414 Posts
Re: How to shorten a field?
Feb 29, 2012 03:38 AM|LINK
hi, refer below code
<a href="#" id="lnkShowUserMessageModal" runat="server"> <%= Eval("strContent").ToString().Length > 40 ? Eval("strContent").ToString().Substring(0, 40) +"..." : Eval("strContent").ToString()%> </a>In Vb.Net
<%# IIF(Eval("Description").ToString().Length>100, Eval("Description").ToString().Substring(0,100) & "...",Eval("Description").ToString()) %>
Karthick S
umairaslam22
Contributor
3990 Points
845 Posts
Re: How to shorten a field?
Feb 29, 2012 03:45 AM|LINK
If you are retrieving it from database you can achieve it via sql query here is the example
Select
(Case When LEN(strContent) > 40 Then Left(strcontent,40) + '...' Else strcontent End ) as strContent
From yourTableName
MCP
Blog
Please remember to Mark as answer if any post help you , it help others to find right solution in less time
sreejukg
All-Star
27509 Points
4097 Posts
Re: How to shorten a field?
Feb 29, 2012 03:45 AM|LINK
Try this
<%#Eval("strContent").ToString().Length > 40 ? Eval("strContent").ToString().Substring(0,40) + "..." : Eval("strContent").ToString()%>
eval href
My Blog
prakashslm
Member
256 Points
87 Posts
Re: How to shorten a field?
Feb 29, 2012 04:10 AM|LINK
Hi,
try this
public string TruncateAtWord( string input, int length ) { if(input == null || input.Length < length) return input; int iNextSpace = input.LastIndexOf( " ", length ); return string.Format( "{0}...", input.Substring( 0, (iNextSpace > 0) ? iNextSpace : length ).Trim() ); }if you want to you in whole project try to add this method in masterpage
Thanks & Regards,
Prakash
http://prakash84slm.blogspot.com
Remember to click “Mark as Answer” on the post, if it helps you.
Kurai
Member
233 Points
182 Posts
Re: How to shorten a field?
Feb 29, 2012 02:17 PM|LINK
Thanks everyone.. :)
shafkatlee
Member
152 Points
53 Posts
Re: How to shorten a field?
Mar 05, 2012 09:11 AM|LINK
Hi,
you can try this:
public static string GetSubString(string text, int maxDescriptionSize = 0) { maxDescriptionSize = maxDescriptionSize.Equals(0) ? MaxDescriptionSize : maxDescriptionSize; if (!string.IsNullOrWhiteSpace(text) && text.Length > maxDescriptionSize) { text = string.Concat(text.Substring(0, maxDescriptionSize), "..."); } return text; } And call this function while grid bind.eval href