Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Limit length (number of characters) returned in <%#XPath("description")%> ?

Limit length (number of characters) returned in <%#XPath("description")%> ?

Scheduled Pinned Locked Moved XML / XSL
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cbvoss
    wrote on last edited by
    #1

    I'm using an XMLDataSource to pull rss feeds into my site. Some of the feeds have really long descriptions, so I'd like to limit the length of the description fields, and then append a "..." to the end. Is there any way to do that?

    C 1 Reply Last reply
    0
    • C cbvoss

      I'm using an XMLDataSource to pull rss feeds into my site. Some of the feeds have really long descriptions, so I'd like to limit the length of the description fields, and then append a "..." to the end. Is there any way to do that?

      C Offline
      C Offline
      cbvoss
      wrote on last edited by
      #2

      Found solution. Here's ASP.net code in case it helps anyone else: <pre> <asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1" BackColor="#333333" BorderStyle="None" GridLines="Vertical" BorderColor="#333333" BorderWidth="0px"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#XPath("pubDate")%>' Font-Names="Verdana" Font-Size="XX-Small"></asp:Label><br /> <asp:HyperLink ID="HyperLink1" runat="server" Text='<%#XPath("title")%>' NavigateUrl='<%#XPath("link")%>' Target="_blank" Font-Names="Verdana" Font-Size="Small"></asp:HyperLink><br /> <asp:Label ID="description_label" runat="server" Text='<%#XPath("description")%>'></asp:Label><br /> <br /> </ItemTemplate> </asp:DataList> Here's the code behind: <pre> Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound Dim ShortDescriptionLabel As Label = CType(e.Item.FindControl("description_label"), Label) If ShortDescriptionLabel.Text.Length > 200 Then ShortDescriptionLabel.Text = ShortDescriptionLabel.Text.Substring(0, 200) & "..." End If ShortDescriptionLabel.Text = ShortDescriptionLabel.Text End Sub

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups