How to fix display problem of Ajax Tool Kit's Accordion when it is binded with Craigslist Feed?

Hello,

I have solved the display problem: Instead of fetching feed directly from Craigslist, I am fetching data from Yahoo Pipe. I believe Yahoo Pipe takes care of many Rss syntax error, and I believe, originally I was having sometimes problem in my webpage as some elements were semantically incorrect at craigslist rss feed. But as now I am fetching data from Yahoo Pipe, the main problem is solved.
However, I have another question, which is at below:
.......................................................................................................................................................

I need some help. Please read my problem scenerio:

I made a webpage that utilizes .NET 3.5 C# and Ajax tool kit's Accordion control to show rss feed from Craigslist.
My question is:
how to modify an element of XDocument?

Please see the below code to understand my  question:

 var feeds = from feed in xdoc.Descendants(rss + "item")
                    select new
                    {
                        title = feed.Element(rss + "title").Value,
                        url = feed.Element(rss + "link").Value,
                        description = feed.Element(rss + "description").Value<------------------------***

                    };

   
        Accordion1.DataSource = feeds;
        Accordion1.DataBind();

My question is: after I get the value of description, title, url and save it into varriable feeds, how can I modify "descrition" of feeds?

An example would be: "description" has 1000 words, with images; I want to show only 500 words and no images. How to do this? I know I can use many string methods like Replace or remove,

but if I want to do multiple string operation on description, to show only specific contents, before it gets saved in "var feeds" or gets binded with "Accordion1", how to do that?

Another example can be, I want to replace some specific characters like & or - and also show only the first 100 words.  Say if the description node has "Mary has an Apple. Mary has a book. Mary is playing," I would like to show only 20 characters: "Mary has an Apple. M" and then bind the modified description with the Accodion.

Please tell me how to do multiple string operations on elements of XDocument before the var feed get binded with a control?

Please answer.

My latest code behind file is at below, where I am fetching Craigslist feed via Yahoo Pipe.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;


public partial class _Default : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        XNamespace rss = "http://purl.org/rss/1.0/";
        string selectedValue = DropDownList1.SelectedValue;
        string url, firstPart, secondPart= null;

        if (selectedValue.Length == 0)
        {
            url = "http://sfbay.craigslist.org/sof/index.rss";
        }
        else
        {
            firstPart = "http://sfbay.craigslist.org/search/sof?query=";
            secondPart = "&catAbbreviation=sof&format=rss";
            url = firstPart + selectedValue + secondPart;
        }
        XDocument xdoc = XDocument.Load(url);
        var feeds = from feed in xdoc.Descendants(rss + "item")
                    select new
                    {
                        title = feed.Element(rss + "title").Value,
                        url = feed.Element(rss + "link").Value,
                        description = feed.Element(rss + "description").Value
                    };
        Int32 listCount = xdoc.Descendants(rss + "description").Count();  
       
        Accordion1.DataSource = feeds;
        Accordion1.DataBind();
        Accordion1.SelectedIndex = -1;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        XDocument xdoc = XDocument.Load("http://pipes.yahoo.com/pipes/pipe.run?_id=78ecc6a683ee31295094af9ba5b66df4&_render=rss");
      //  XNamespace rss = "http://purl.org/rss/1.0/";
        var feeds = from feed in xdoc.Descendants("item")
                    select new
                    {
                        title = feed.Element("title").Value,
                        url = feed.Element("link").Value,
                        description = feed.Element("description").Value

                    };

        Accordion1.DataSource = feeds;
        Accordion1.DataBind();
    }
}







<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
    .accordionHeader
{
    border: 1px solid #EBDDE2;
    color: white;
    background-color: 	#5E5A80;
	font-family: Arial, Sans-Serif;
	font-size: 12px;
	font-weight: bold;
    padding: 5px;
    margin-top: 5px;
    cursor: pointer;
}
.accordionContent
{
    border: 2px solid #EBDDE2;
    color: #444444;
	font-family: Arial, Sans-Serif;
	font-size: 12px;

    padding: 5px;
    margin-top: 5px;
    
}
#content
{
   width:700px;
   height:550px;
   overflow:auto; 
   
}
    
    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value="">All Software/Qa/DBA Job</asp:ListItem>
            <asp:ListItem Value="Senior+Software+Engineer">Senior Software Engineer</asp:ListItem>
            <asp:ListItem Value="Junior+Software+Engineer">Junior Software Engineer</asp:ListItem>
            <asp:ListItem Value="ASP+.NET">ASP .NET</asp:ListItem>
            <asp:ListItem Value="Front+End+Engineer">Front End Engineer</asp:ListItem>
            <asp:ListItem Value="C%23+ASP+.NET">C# ASP .NET</asp:ListItem>
            <asp:ListItem Value="JAVA">Java</asp:ListItem>
            <asp:ListItem Value="PHP">PHP</asp:ListItem>
            <asp:ListItem Value="Ruby+On+Rails">Ruby on Rails</asp:ListItem>
            <asp:ListItem Value="Flash">Flash</asp:ListItem>
            <asp:ListItem Value="SQL">SQL</asp:ListItem>
            <asp:ListItem Value="Database">Database</asp:ListItem>
            <asp:ListItem Value="Perl">Perl</asp:ListItem>
            <asp:ListItem Value="COBOL">COBOL</asp:ListItem>
            <asp:ListItem Value="Web+2.0">Web 2.0</asp:ListItem>
            <asp:ListItem Value="Web+Developer">Web Developer</asp:ListItem>
            <asp:ListItem Value="Software+Developer">Software Developer</asp:ListItem>
            <asp:ListItem Value="Programmer Analyst">Programmer Analyst</asp:ListItem>
            <asp:ListItem Value="JavaScript">Java Script</asp:ListItem>
            <asp:ListItem Value="JQuery">JQuery</asp:ListItem>
        </asp:DropDownList>
                  
        <asp:Button ID="Button1" runat="server" Text="Submit Query" onclick="Button1_Click"/>
        

 
    </div>
    <div id="content">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <cc1:Accordion ID="Accordion1" runat="server" 
         
         HeaderCssClass="accordionHeader"
         HeaderSelectedCssClass="accordionHeader"
         ContentCssClass="accordionContent"
         AutoSize="None" 
         FadeTransitions="true"
         TransitionDuration="250"
         FramesPerSecond="30"
         RequireOpenedPane="false"
         SuppressHeaderPostbacks="True" 
         SelectedIndex="-1" 
         
         >
         <HeaderTemplate >
            <%# Eval("title") %> 
           
         </HeaderTemplate> 
         <ContentTemplate> <div id="accordionContent">
            <%#Eval("description")%></div>
            
         </ContentTemplate>        
   
</cc1:Accordion>
<br /><br />
   </div>
   
    </form>
</body>
</html>
...........................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;


public partial class _Default : System.Web.UI.Page 
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        XNamespace rss = "http://purl.org/rss/1.0/";
        string selectedValue = DropDownList1.SelectedValue;
        string url, firstPart, secondPart= null;

        if (selectedValue.Length == 0)
        {
            url = "http://sfbay.craigslist.org/sof/index.rss";
        }
        else
        {
            firstPart = "http://sfbay.craigslist.org/search/sof?query=";
            secondPart = "&catAbbreviation=sof&format=rss";
            url = firstPart + selectedValue + secondPart;
        }
        XDocument xdoc = XDocument.Load(url);
        var feeds = from feed in xdoc.Descendants(rss + "item")
                    select new
                    {
                        title = feed.Element(rss + "title").Value,
                        url = feed.Element(rss + "link").Value,
                        description = feed.Element(rss + "description").Value
                    };
        Int32 listCount = xdoc.Descendants(rss + "description").Count();  
        
        Accordion1.DataSource = feeds;
        Accordion1.DataBind();
        Accordion1.SelectedIndex = -1;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        XDocument xdoc = XDocument.Load("http://sfbay.craigslist.org/sof/index.rss");
        XNamespace rss = "http://purl.org/rss/1.0/";
        var feeds = from feed in xdoc.Descendants(rss + "item")
                    select new
                    {
                        title = feed.Element(rss + "title").Value,
                        url = feed.Element(rss + "link").Value,
                        description = feed.Element(rss + "description").Value

                    };

        Accordion1.DataSource = feeds;
        Accordion1.DataBind();
    }
}

Open in new window

ErrorImage.jpg
LVL 3
ashley2009Asked:
Who is Participating?
 
ashley2009Author Commented:
Hello, I have also solved the second part of the problem: it seems that we can call a method from the query block:

 var feeds = from feed in xdoc.Descendants("item")
                    select new
                    {
                        title = feed.Element("title").Value,
                        url = feed.Element("link").Value.Replace("http://us.rd.yahoo.com/dailynews/rss/topstories/*",""),
                        description = modify(feed.Element("description").Value),
                        date = feed.Element("pubDate").Value
                    };
     

        Accordion1.DataSource = feeds;
        Accordion1.DataBind();

    }

    private object modify(string p)
    {
        p = p.Replace("http://us.rd.yahoo.com/dailynews/rss/topstories/*", "");
        p = p.Replace("&", "&amp;");
        return p+"AHA";
    }

Therefore, this problem is solved for now as I now know how to modify element that is inside of a block.

I had two questions:

First was:

How to fix display problem of Ajax Tool Kit's Accordion when it is binded with Craigslist Feed?

And the second was:

how to do multiple string operation on an element of XDocument before that var feed object gets binded with some control.

I have solved both of the problem.

First One's solution:

By creating Yahoo Pipe for craigslist RSS feed, I got rid of problems that were coming from some specific craigslist entry.

Second One's Solution:

Now I know that a method can ne called from a query block. Therefore, I will be able to do string operation on an element before the feed object gets binded with some control.

Therefore, this question got resolved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.