Solved

Pass Data from Parent window to query in Child Window

Posted on 2010-08-16
8
974 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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