Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I truncate text in Datalists?

Status
Not open for further replies.

satchi

Programmer
Sep 15, 2003
104
US
Hi, I'm working w/ ASP.net 2.0 and I have a datalist with this element within the <ItemTemplate> tag:

<asp:Label ID="descLabel" runat="server" Text='<%# Eval("desc", "{0}") %>' />

This element basically displays the description text. Is there a simple way to truncate this text file to show only 24 characters instead of the whole thing?

I was thinking about the Eval("desc", "{0}") portion where perhaps I can limit it by something like {0:...24} ...ahh I don't know what i'm doing.

Any suggestions?
 
Personally, I would truncate the data in the sql that pulls the data into your datasource. You can also use the ItemDatabound event and truncate the text there.

Jim
 
Thanks for the post jbenson001. Initially I had a short and long description field but I wanted to combine them thus using the long description field as a short one but simply cutting some text off.

I was doing some research on the ItemDatabound event, but I'm still learning asp.net (2.0) so I think I'll need to spend a bit of time getting to know more of the events.

I did some looking around the Substring() method and this seemed to do the trick.

Text='<%# (Eval("desc", "{0}").ToString()).Substring(0,24) + "..." %>' />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top