Solved

Pass Data from Parent window to query in Child Window

Posted on 2010-08-16
8
980 Views
Last Modified: 2013-11-12
Hi experts..

I have a silverlight page which has a list of users (for example) and I am trying to get it so that when i click on it, a child window appears and within that window there is another datagrid that is to be populated with data from tables based on the user i selected from the list box.

I am having difficultly passing userID to the wcf query behind the datagrid in the child window. The datagrid returns empty.

could you please correct me in where i am going wrong please..the code i have is below

**this code i have in the MainPage.xaml for the listbox_selected changed event.**
            ServiceReference1.site test = (site)ListBox1.SelectedItem;
            ChildShowDeviceResults cmod = new ChildShowDeviceResults();
           
            cmod.DataContext = test;
            cmod.Show();

**in the ChildWindow I have placed a textbox just to see if i can bind a value to it from the datacontext from the MainPage. When i load the childwindow, i can see taht the textbox shows the actual id of the user i selected, but then when i try to run the Page_Loaded event, the query doesnt seem to take the value into its parameters**

 private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            _ServiceClient client = new _ServiceClient();
            client.getResultsByIDCompleted += new EventHandler<getResultsByIDCompletedEventArgs>(client_getResultsByIDCompleted);
            client.getResultsByIDAsync(Convert.ToInt32(textBox1.Text));

        }

this does not seem to work.


any help would be much appreciated.
0
Comment
Question by:baz86
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33453259
Perhaps these examples/articles can help you further

Passing Values between forms in Silverlight
http://www.c-sharpcorner.com/UploadFile/prvn_131971/PassingValuesSilverlight11192008060441AM/PassingValuesSilverlight.aspx

Silverlight How To Pass Values Between Pages or Forms
http://www.xploredotnet.com/2009/12/silverlight-how-to-pass-values-between.html
0
 
LVL 21

Accepted Solution

by:
tovvenki earned 500 total points
ID: 33453541
Hi,
Are you still having facing issues,
you can also pass the data through the constructor
ServiceReference1.site test = (site)ListBox1.SelectedItem;
            ChildShowDeviceResults cmod = new ChildShowDeviceResults(selectedsite);
in the child window's constructor get the values and use it to get the data from the service

Thanks and regards,
Venki
0
 

Author Comment

by:baz86
ID: 33453640
Hi Dhaest and tovvenkit,
Thank you both for your replies.
@Dhaest. The links were useful but as i'm a beginner in all this i'm not sure how i could work that with the list box in form 1.
@tovvenkit. Yes still having issues unfortunately. Would you please be able to expand on the code in both forms to what i should be looking to get because im having no luck. I can't seem to access the ID of the selected item and pass that on.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Comment

by:baz86
ID: 33453702
This is the xaml for the first page and it shows how the structure of the list box for your information
<ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock x:Name="txtSiteID" Text="{Binding site_id}" Margin="5" Foreground="Red"/>
                                        <TextBlock Text="{Binding site_name}" Margin="5" Style="{StaticResource TitleBlock}"/>
                                        <TextBlock Text="{Binding site_postcode}" Margin="5" Style="{StaticResource TitleBlock}"/>
                                    </StackPanel>

                                </DataTemplate>
                            </ListBox.ItemTemplate>

Open in new window

0
 

Author Comment

by:baz86
ID: 33453796
On page1 i can set the .ItemSource for page2 as whatever is selected in the list box on page one. But I can't seem to pass say the USERID from the listbox into a query in page 2 each time i call a new instance of page 2....any ideas?
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 33458088
It sounds like you are trying to do master/detail linking.  This article walks you through it.
http://www.silverlight.net/learn/videos/all/simple-masterdetails-with-datagrid/
0
 

Author Comment

by:baz86
ID: 33468876
Hi tovvenki,
Your suggestion of passing the value in the constructor worked like a charm! Thanks!!
0
 

Author Closing Comment

by:baz86
ID: 33468881
suggestion of passing the value in the constructor worked like a charm! Thanks!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

751 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