when i kept dg.itemsource or dg.datacontext it is not coming i have tried
here the code.
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="Drop Page" Loaded="Page_Loaded" >
xaml.cs
private void Page_Loaded(object sender, RoutedEventArgs e)
{
prod = new ProductServiceReference.ProductServiceClient();
prod.GetProductsByCategoryCompleted+= prodservice_GetProductscompleted;
prod.GetCategoriesCompleted += prodservice_GetCategoriescompleted;
prod.GetProductsAsync();
prod.GetCategoriesAsync();
}
private void prodservice_GetCategoriescompleted(object sender, ProductServiceReference.GetCategoriesCompletedEventArgs e)
{
lstcategores.ItemsSource = e.Result;
}
private void lstcategores_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int CategoryID = ((ProductServiceReference.Categories)((ListBox)sender).SelectedItem).CategoryID;
prod.GetProductsByCategoryAsync(CategoryID);
}
private void prodservice_GetProductscompleted(object sender, ProductServiceReference.GetProductsByCategoryCompletedEventArgs e)
{
DG.DataContext = e.Result;
}
in Services
public bool GetProductsByCategory(int categoryid)
{
NorthwindClassesDataContext db = new NorthwindClassesDataContext();
List
try
{
prod = (from p in db.Products
where p.CategoryID == categoryid
select new Products { ProductID = p.ProductID, ProductName = p.ProductName }).ToList();
}
catch (Exception)
{
throw new FaultException("no Categories are defined");
}
return true;
}
Mamta MPosted Oct 7, 2011, 1:57 AM
lstcategores.ItemsSource = e.Result;
working? Is the listbox getting populated? If yes, and if only the SelctionChanged is not working, then Use LinQPad to see if your Linq query given in the service is working successfully or not...the linq query could be causing an issue.