Click here to Skip to main content
15,912,069 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi
I am developing a Silverlight web application that uses WCF services to interact with database. I return a arraylist from DAL layer to Xaml.cs but could not bind it to Datagrid.
My Code section is as follows:
if (e.Error != null)
{
    //Error Condition
}
else
{
    dataGrid1.ItemsSource = e.Result;
}


The data is not getting binded if I use datagrid1.ItemSource = e.Result;..
Please give your valuable suggestions in this regard.

Thanks
Naresh.
Posted
Updated 4-Mar-11 7:47am
v2

What does e.result contain? Is it a collection?

Note: Arraylists are not supported in Silverlight and you need to use an ObservableCollection.

Any IEnumerable can be used as an itemssource, not just ObservableCollection.
 
Share this answer
 
v3
Comments
Abhinav S 12-May-11 0:11am    
Good point, Mark. Thanks for the correction.
S.M.Naresh 13-May-11 7:43am    
Thanks for your reply.. Can you discuss in detail or give example regarding bind to SL Datagrid.
You need to Either enable AutoGenerateColumns
dataGrid1.AutoGenerateColumns = true;


OR you can Add column and specify binding

XML
<sdk:DataGrid AutoGenerateColumns="False" Height="185" HorizontalAlignment="Left" Margin="33,66,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="325">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Test" Width="Auto" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900