Limit length (number of characters) returned in <%#XPath("description")%> ?
-
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?
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