# Displaying data in Next Page based on previous Page's List Selection

**URL:** <https://forum.kirupa.com/t/displaying-data-in-next-page-based-on-previous-pages-list-selection/319094>\
**Category:** programming\
**Created:** [February 8, 2011, 11:05pm UTC](https://forum.kirupa.com/t/displaying-data-in-next-page-based-on-previous-pages-list-selection/319094 "2011-02-08T23:05:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newtoWP7](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@newtoWP7](https://forum.kirupa.com/u/newtoWP7)\
**Post date:** [February 8, 2011, 11:05pm UTC](https://forum.kirupa.com/t/displaying-data-in-next-page-based-on-previous-pages-list-selection/319094/1 "2011-02-08T23:05:14Z")

</div>

Hi,

I found the Simple navigation and the Passing data between pages tutorials helpful. I tried to create a list in one page and load the next page values based on the selection.

Here is my XML structure:  
\<Class\>  
\<Classbook\>  
\<Name\>Database \</Name\>  
\<Text\>XML XAML \</Text\>  
\<Reference\>SQL SQLSErver \</Reference\>  
\</Classbook\>  
\<Classbook\>  
\<Name\>Programming \</Name\>  
\<Text\>VC# C# \</Text\>  
\<Reference\>C++ VC++ \</Reference\>  
\</Classbook\>  
\</Class\>

I have a panorama page with a listbox which displays the class name but I want to display the booktext and reference in the next page in textblock . here is my code:  
XDocument XMLFile=XDocument.Load(“Class.xml”);  
// Set the data context of the listbox control to the sample data

```
var classes = from query in XMLFile.Descendants("Classbook")     

select new Class {  
    Name = (string)query.Element("Name")    
};    

MainListBox.ItemsSource = classes;  
this.Loaded += new RoutedEventHandler(MainPage_Loaded); 

```

}  
// Handle selection changed on ListBox

private void MainListBox\_SelectionChanged(object sender, SelectionChangedEventArgs e) {  
// If selected index is -1 (no selection) do nothing  
if (MainListBox.SelectedIndex == -1) return;  
// Navigate to the new page  
NavigationService.Navigate(new Uri("/DetailsPage.xaml?Class=" + Name, UriKind.Relative));  
// Reset selected index to -1 (no selection)  
MainListBox.SelectedIndex = -1; }

The second Page has this:

XDocument XMLFile = XDocument.Load(“Class.xml”);  
//Page Title is a textblock displaying Class Name  
PageTitle.Text = Name;  
var Textbook= from query in XMLFile.Descendants(“Class”)  
where query.Descendants(“Name”)=Name  
select new Book {

```
      Textbook =(string)query.Element("Text") 
}; 
BookTitle.Text= Textbook; 
var Reference = from query in XMLFile.Descendants("Book")  
    where query.Descendants("Name")=Name 
select new Book {  
    Reference = (string)query.Element("Reference")  
};  
TextBlock1.Text = Reference; 

```

Nothing is seen in the second page. Not even the page title. What am I doing wrong? Is the code correct? I really appreciate your help.
