Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Will this Remove characters?

I just want to know if there is any problems with this code

<%# DataBinder.Eval(Container.DataItem, "diaryEntry").ToString().Substring( 0, DataBinder.Eval(Container.DataItem, "diaryEntry").ToString().Length < 255 ? DataBinder.Eval(Container.DataItem, "diaryEntry").ToString().Length : 255 ) %>

I basically want to limit the post preview to just a few characters.
0
fallenarmies
Asked:
fallenarmies
  • 2
1 Solution
 
David H.H.LeeCommented:
fallenarmies,
Put all this in a function.
eg:
<%#PostData(DataBinder.Eval(Container.DataItem, "diaryEntry"))%>

public string PostData(string strItem)
{
  if(strItem.Length<255)
    return strItem
 else
   return strItem.Substring(0,255)
}
0
 
fallenarmiesAuthor Commented:
should this be inline or in codebehind?
0
 
David H.H.LeeCommented:
fallenarmies ,
Both work for inline or code-behind as well.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now