[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populate an AJAX Accordian control with a RSS feed via code behind

Posted on 2007-07-25
4
Medium Priority
?
607 Views
Last Modified: 2013-11-18
All i want to do is populate an AJAX accordian control with an RSS feed.  Everything works fine until i add it to the accordian control.  When i execute, i'm getting the following error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 4:      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 5:          Dim rssMovies As RssToolkit.Rss.RssDocument = RssToolkit.Rss.RssDocument.Load(New System.Uri("http://movies.msn.com/rss/topboxoffice"))
Line 6:          Movies.DataSource = rssMovies.SelectItems()
Line 7:          Movies.DataBind()
Line 8:      End Sub


Here is the ASPX file - and the code behind follows:
##################################################

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Stupid.aspx.vb" Inherits="Timbersnow.Stupid" %>
<%@ Register Assembly="AjaxControlToolkit, Version=1.0.10301.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
    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>Untitled Page</title>
    <link href="Includes/Ajax.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="width:425px;">
   
       <cc1:Accordion ID="rssAccordian" runat="server"
                           SelectedIndex="0"
                           HeaderCssClass="accordionHeader"
                           ContentCssClass="accordionContent"
                           FadeTransitions="true"
                           FramesPerSecond="40"
                           TransitionDuration="250"
                           AutoSize="None">
        <Panes>
       
        <cc1:AccordionPane ID = "AccordionPane1" runat = "server">
          <Header>
            <a href = "" onclick = "return false;" class = "accordionLink"> Local Weather</a>
          </Header>
          <Content>
             
            <div style="font-family:Verdana;
                        color:Gray;
                        font-size:10px;
                        padding-left:5px;
                        padding-right:18px;
                        text-align: Left;
                        height:250px;
                        width:400px;">

                <asp:Image ID="ImgMovies" runat="server"
                 ImageUrl="http://entimg.msn.com/i/ms/movies_logo.gif"
                  style="text-align: left" />
                    
                   entertainment<asp:DataGrid runat="server" id="Movies"
                     AutoGenerateColumns="False"
                     Font-Size="10pt"
                     HeaderStyle-Font-Bold="True"
                     HeaderStyle-HorizontalAlign="Left"
                     HeaderStyle-BackColor="Navy"
                     HeaderStyle-ForeColor="White"
                     HeaderStyle-Font-Size="10pt"
                     ShowHeader="false"
                     AlternatingItemStyle-BackColor="#eeeeee"
                     CellPadding="4"
                     BorderColor="blue"
                     ForeColor="#333333"
                     GridLines="None" style="text-align: left">
                               
                      <Columns>
                        <asp:TemplateColumn HeaderText="Today's News Headlines">
                          <ItemTemplate>
           
                          <div style="font-size:13px;
                                        background-color:Gray;
                                        color:White;
                                         font-weight:bold;">
                                <%# DataBinder.Eval(Container.DataItem, "title")%><br />
                          </div>
                             <div style="font-size:10px;
                                        margin-left:10px;">
                                <%#DataBinder.Eval(Container.DataItem, "description")%><br />
           
           
                                <div style="font-size:9px;
                                            font-style:italic;
                                            text-align:right;">
                                   <a href=' <%#DataBinder.Eval(Container.DataItem, "link")%>'>... more here</a>
                                </div>
                             
           
           
                                <div style="font-size:9px;
                                            font-style:italic;
                                            text-align:right;">
                                  <%#DataBinder.Eval(Container.DataItem, "pubDate")%><br />
                                </div>
           
                           </div>

                          </ItemTemplate>
                        </asp:TemplateColumn>
                      </Columns>
                        
                      <selecteditemstyle backcolor="#E2DED6" font-bold="True" forecolor="#333333" />
                      <pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Left" />
                      <alternatingitemstyle backcolor="White" forecolor="#284775" />
                      <itemstyle backcolor="#F7F6F3" forecolor="#333333" />
                 
                      <headerstyle backcolor="#5D7B9D"
                                   font-bold="False"
                                   font-size="12pt"
                                   forecolor="White"
                                   horizontalalign="Left" />
               
                </asp:DataGrid>
               
                </Content>
            </cc1:AccordionPane>
        </Panes>
    </cc1:Accordion>
 </div>
       
   
    </form>
</body>
</html>


CODE BEHIND:
##################################

Public Partial Class Stupid
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim rssMovies As RssToolkit.Rss.RssDocument = RssToolkit.Rss.RssDocument.Load(New System.Uri("http://movies.msn.com/rss/topboxoffice"))
        Movies.DataSource = rssMovies.SelectItems()
        Movies.DataBind()
    End Sub
End Class


 
0
Comment
Question by:timbersnow
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 1500 total points
ID: 19569644
check for Nothing "null" C# first before you bind
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim rssMovies As RssToolkit.Rss.RssDocument = RssToolkit.Rss.RssDocument.Load(New System.Uri("http://movies.msn.com/rss/topboxoffice"))

If Not(rssMovies) Is nothing then
     Movies.DataSource = rssMovies.SelectItems()
        Movies.DataBind()
    End Sub

one more thing, see how your object "ressMovies" is initilized
Dim rssMovies as New  RssToolkit.Rss.RssDocument

Sorry I am kind of Rusty in VB.NET. I can tell you the error is just telling you the object is NOT initialized properly


Good luck
0
 

Author Comment

by:timbersnow
ID: 19569743
I get the null ... but if i do not include it in the AJAX Accordian control, it works fine.  And as far as i can tell, it IS initialized correctly and it SHOULD contain the correct data.

Wierd ...

Gp.

0
 

Author Comment

by:timbersnow
ID: 19569774
nah ... just got ...

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 6:          Dim rssMovies As RssToolkit.Rss.RssDocument = RssToolkit.Rss.RssDocument.Load(New System.Uri("http://movies.msn.com/rss/topboxoffice"))
Line 7:          If Not (rssMovies) Is Nothing Then
Line 8:              Movies.DataSource = rssMovies.SelectItems()
Line 9:              Movies.DataBind()
Line 10:         End If
 
0
 

Author Comment

by:timbersnow
ID: 19569914
I got it ... did it a different way ...


Here's what i did ... if anybody in expertsland cares ...

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Stupid.aspx.vb" Inherits="Timbersnow.Stupid" %>

<%@ Register Assembly="RssToolkit" Namespace="RssToolkit.Web.WebControls" TagPrefix="cc2" %>
<%@ Register Assembly="AjaxControlToolkit, Version=1.0.10301.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
    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>Untitled Page</title>
    <link href="Includes/Ajax.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="width:425px;">
    <cc2:RssDataSource ID="rssMovies" runat="server" Url="http://movies.msn.com/rss/topboxoffice">
     </cc2:RssDataSource>

       <cc1:Accordion ID="rssAccordian" runat="server"
                           SelectedIndex="0"
                           HeaderCssClass="accordionHeader"
                           ContentCssClass="accordionContent"
                           FadeTransitions="true"
                           FramesPerSecond="40"
                           TransitionDuration="250"
                           AutoSize="None">
        <Panes>
       
        <cc1:AccordionPane ID = "AccordionPane1" runat = "server">
          <Header>
            <a href = "" onclick = "return false;" class = "accordionLink"> Local Weather</a>
          </Header>
          <Content>
             
            <div style="font-family:Verdana;
                        color:Gray;
                        font-size:10px;
                        padding-left:5px;
                        padding-right:18px;
                        text-align: Left;
                        height:250px;
                        width:400px;">

                <asp:Image ID="ImgMovies" runat="server"
                 ImageUrl="http://entimg.msn.com/i/ms/movies_logo.gif"
                  style="text-align: left" />
                    
                   entertainment
                   <asp:DataGrid runat="server" id="Movies"
                        DataSourceID="rssMovies"
                     AutoGenerateColumns="False"
                     Font-Size="10pt"
                     HeaderStyle-Font-Bold="True"
                     HeaderStyle-HorizontalAlign="Left"
                     HeaderStyle-BackColor="Navy"
                     HeaderStyle-ForeColor="White"
                     HeaderStyle-Font-Size="10pt"
                     ShowHeader="false"
                     AlternatingItemStyle-BackColor="#eeeeee"
                     CellPadding="4"
                     BorderColor="blue"
                     ForeColor="#333333"
                     GridLines="None" style="text-align: left">
                               
                      <Columns>
                        <asp:TemplateColumn HeaderText="Today's News Headlines">
                          <ItemTemplate>
           
                          <div style="font-size:13px;
                                        background-color:Gray;
                                        color:White;
                                         font-weight:bold;">
                                <%# DataBinder.Eval(Container.DataItem, "title")%><br />
                          </div>
                           
           
                          <div style="font-size:10px;
                                        margin-left:10px;">
                                <%#DataBinder.Eval(Container.DataItem, "description")%><br />
           
           
                                <div style="font-size:9px;
                                            font-style:italic;
                                            text-align:right;">
                                   <a href=' <%#DataBinder.Eval(Container.DataItem, "link")%>'>... more here</a>
                                </div>
                             
           
           
                                <div style="font-size:9px;
                                            font-style:italic;
                                            text-align:right;">
                                  <%#DataBinder.Eval(Container.DataItem, "pubDate")%><br />
                                </div>
           
                           </div>

                          </ItemTemplate>
                        </asp:TemplateColumn>
                      </Columns>
                        
                      <selecteditemstyle backcolor="#E2DED6" font-bold="True" forecolor="#333333" />
                      <pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Left" />
                      <alternatingitemstyle backcolor="White" forecolor="#284775" />
                      <itemstyle backcolor="#F7F6F3" forecolor="#333333" />
                 
                      <headerstyle backcolor="#5D7B9D"
                                   font-bold="False"
                                   font-size="12pt"
                                   forecolor="White"
                                   horizontalalign="Left" />
               
                </asp:DataGrid>
               
                </Content>
            </cc1:AccordionPane>
        </Panes>
    </cc1:Accordion>
   
 </div>
       
   
    </form>
</body>
</html>

Cheers,

Gp.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question