Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

returning x chars of Eval("..")

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin Blount - 29 Nov 2007 21:50 GMT
I'm putting a radG:GridTemplateColumn together (which is probably
irelevant), and within it I'm using a Label, as so:

<asp:Label ID="defaultDescription" runat="server" Text='<%#
Eval("description") %>'></asp:Label>

Fo this Label, I'd like to only show the first 50 chars of the
"description", but I've no idea how to change the Eval to do this.. is
there a way?
Nicholas Paldino [.NET/C# MVP] - 29 Nov 2007 22:25 GMT
Kevin,

   The Eval method returns an object, which you can call ToString on and
then call substring on:

<%# Eval("description").ToString().Substring(0, 50) %>

   Or, assuming description is a string field (and you know this), you
could just cast:

<% ((string) Eval("description")).Substring(0, 50) %>

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> I'm putting a radG:GridTemplateColumn together (which is probably
> irelevant), and within it I'm using a Label, as so:
[quoted text clipped - 5 lines]
> "description", but I've no idea how to change the Eval to do this.. is
> there a way?
Mythran - 30 Nov 2007 16:49 GMT
> Kevin,
>
[quoted text clipped - 17 lines]
>> "description", but I've no idea how to change the Eval to do this.. is
>> there a way?

<asp:Label ID="defaultDescription" runat="server" Text='<%#
Eval("description") == null ? string.Empty : ((string)
Eval("description")).Substring(0, 50) %>

just to be on the safe side :P

Mythran
Kevin Blount - 03 Dec 2007 19:57 GMT
> > Kevin,
>
[quoted text clipped - 31 lines]
>
> - Show quoted text -

Thanks guys.. apprecaite the replies.

I ended up creating anew method, where i can do much more string
manipulation, then return the result. My ASPX page now uses <%#
getDescription() %> (there I can replace chars, truncate the length,
search for "http://" and replace with "<a href='http://'" for example.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.