Solved

Pass Data from Parent window to query in Child Window

Posted on 2010-08-16
8
968 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
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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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:tedbilly
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now